单击按钮时应用程序崩溃。无法启动活动ComponentInfo

时间:2015-11-29 02:21:41

标签: android

我知道之前有这样的问题。我已经尝试了从线程中给出的一些解决方案,但它似乎没有解决我的应用程序的错误

这是我的第二个活动的android.manifest文件

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <activity
        android:name=".RevGPAActivity"
        android:label="@string/title_activity_rev_gpa">
        <intent-filter>
            <action android:name="com.example.user.testapp.RevGPAActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <!-- ATTENTION: This was auto-generated to add Google Play services to your project for
         App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

这是我的MainActivity

private GoogleApiClient client;
Button start_rev_gpa;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

    //Start Rev GPA
    startRevGPA();
}

public void startRevGPA(){
    start_rev_gpa = (Button)findViewById(R.id.startRevGPA);
    start_rev_gpa.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent("com.example.user.testapp.RevGPAActivity");
                    startActivity(intent);
                }
            }
    );
}

我没有对xml文件做任何事情,如android:onClick或其他任何东西。应用程序挂起约3秒然后停止工作

logcat的

FATAL EXCEPTION: main
                                                                      Process: com.example.user.testapp, PID: 29051
                                                                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.testapp/com.example.user.testapp.RevGPAActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:135)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                                                                       Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                          at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
                                                                          at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
                                                                          at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
                                                                          at com.example.user.testapp.RevGPAActivity.onCreate(RevGPAActivity.java:10)
                                                                          at android.app.Activity.performCreate(Activity.java:5937)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:144) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:135) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5221) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

2 个答案:

答案 0 :(得分:1)

解决了我自己的问题。如果有人偶然发现了同样的错误,那么目标活动应该是扩展Activity而不是ActionBarActivity

here - dotnetfiddler

答案 1 :(得分:0)

正如您在日志文件中看到的那样:You need to use a Theme.AppCompat theme (or descendant) with this activity您可以在项目的style.xml中查看“@ style / AppTheme”,此样式需要parent =“@ style / Theme.AppCompat”或者后代ò< / p>

相关问题