2015-02-03 3 views
0

사용자의 사례 수와 청구서 비용을 입력하는 클래스 용 앱을 만들어야하고 비용이 무엇인지 알려줍니다. 사람이 팁을 추가했습니다. 그것은 작동해야하지만 그것은 내가 확신이 새로운 그래서 오전 매번 나는 에뮬레이터를 실행하면 내 애플 리케이션이 작동을 멈추었다 고 말하고 계속 실행됩니다. 여기 내 코드입니다. 위로 첫 번째 mainactivity. 사람이 그 좋지 않을까 도움이 될 수있는 경우에뮬레이터를 실행할 때 내 안드로이드 앱이 계속 충돌합니다.

package com.example.splitbill; 

import android.support.v7.app.ActionBarActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class MainActivity extends ActionBarActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Button b = (Button) findViewById(R.id.btnCalc); 
     b.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       startActivity(new Intent(MainActivity.this, Calc.class)); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

다음 내 두 번째 활동 석회질

package com.example.splitbill; 

import java.text.DecimalFormat; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Spinner; 
import android.widget.TextView; 

public class Calc extends Activity { 
    double totalOfBill; 
    int numberOfGuests; 
    double perPersonSplit; 
    String groupChoice; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.calc); 
     final EditText guests=(EditText)findViewById(R.id.txtGuests); 
     final EditText bill=(EditText)findViewById(R.id.txtBill); 
     final Spinner group = (Spinner)findViewById(R.id.txtGroup); 
     Button cost = (Button)findViewById(R.id.btnSplit); 
     cost.setOnClickListener(new OnClickListener() { 
     final TextView result = ((TextView)findViewById(R.id.txtResult)); 




      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       totalOfBill = Double.parseDouble(bill.getText().toString()); 
       numberOfGuests = Integer.parseInt(guests.getText().toString()); 
       perPersonSplit = (totalOfBill * .18 +totalOfBill)/numberOfGuests; 
       DecimalFormat currency = new DecimalFormat("$###,###.##"); 
       groupChoice = group.getSelectedItem().toString(); 
       result.setText("Quality is " + groupChoice + "cost is " + currency.format(perPersonSplit)); 

      } 
     }); 
    } 
} 

이라고한다. 어떤 사람이 내가

02-03 16:53:14.297: D/AndroidRuntime(1043): Shutting down VM 
02-03 16:53:14.297: D/AndroidRuntime(1043): --------- beginning of crash 
02-03 16:53:14.312: E/AndroidRuntime(1043): FATAL EXCEPTION: main 
02-03 16:53:14.312: E/AndroidRuntime(1043): Process: com.example.splitbill, PID: 1043 
02-03 16:53:14.312: E/AndroidRuntime(1043): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.splitbill/com.example.splitbill.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.ActivityThread.access$800(ActivityThread.java:144) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.os.Handler.dispatchMessage(Handler.java:102) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.os.Looper.loop(Looper.java:135) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.ActivityThread.main(ActivityThread.java:5221) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at java.lang.reflect.Method.invoke(Native Method) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at java.lang.reflect.Method.invoke(Method.java:372) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
02-03 16:53:14.312: E/AndroidRuntime(1043): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at com.example.splitbill.MainActivity.onCreate(MainActivity.java:16) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.Activity.performCreate(Activity.java:5933) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) 
02-03 16:53:14.312: E/AndroidRuntime(1043):  ... 10 more 
+0

오류 로그 표시 – Nickolaus

+0

오류 로그를 추가했습니다. –

+1

[이 활동과 함께 Theme.AppCompat 테마 (또는 자손)를 사용해야합니다.] (http://stackoverflow.com/questions/21814825/you) -need-to-use-a-theme-appcompat-theme-or-descend-with-this-activity) – njzk2

답변

0

당신은 의존성 아래 Gradle을에 APPCOMPAT 지원 라이브러리를 추가 할 필요가 있다고 생각되어 여기에 오류 로그 나에게 물었다 : 오류 보면

com.android.support:appcompat-v7:21.0.+ 
0

스택 트레이스 로그에서 핵심 메시지는 이것이다 그것은 당신이 AndroidManifest 파일

 <activity 
      android:name=".ui.activity.MainActivity" 
      android:theme="@style/Theme.AppCompat" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
0

에서 각 활동에 대한 AppComapt 테마를 설정해야한다는 것을 의미있어 당신에게

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 

말했다 :

You need to use a Theme.AppCompat theme (or descendant) with this activity. 

이유는 다음과 같습니다. MainActivity은 의 클래스 인 ActionBarActivity을 기반으로합니다. 그리고 리소스의 어딘가에이 라이브러리와 호환되지 않는 테마가 있습니다.

당신은, 당신은 APPCOMPAT 라이브러리를 삭제할 수 있으며, 대신 이것을 사용 (V7까지) 이전 안드로이드 버전을 지원 할 필요가없는 경우 :

public class MainActivity extends Activity { 
... 
} 

(나는 ActivityActionBarActivity에서 기본 클래스를 대체) .

이제 문제가 해결 될 것입니다.긴 안목으로 보면, 당신이에 읽어 추천 :

Android Training도 꽤 일찍 지원 라이브러리의 개념을 도입, 그래서 그들은뿐만 아니라 도움이 될 것이다.

관련 문제