0

I know that there are problems like this before. I have tried some of the solution given from the thread but it did not seem to solve the error for my application

This is my android.manifest file for the second activity

<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>

And here is my 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);
                }
            }
    );
}

I did not do anything on the xml file like android:onClick or anything. The app hangs for about 3 seconds then it stopped working

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) 
Adam
  • 309
  • 1
  • 15

2 Answers2

1

Solved my own problem. If someone stumbled on the same error, the target activity should be extending Activity not ActionBarActivity

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

Community
  • 1
  • 1
Adam
  • 309
  • 1
  • 15
0

As you see in log file: You need to use a Theme.AppCompat theme (or descendant) with this activity could you check `@style/AppTheme" in style.xml of your project, this style need have parent="@style/Theme.AppCompat" or descendant ò

mdtuyen
  • 4,470
  • 5
  • 28
  • 50
  • Hello, i noticed that as well, but do not quite seem to understand what's wtong. The normal styles.xml i have it on "Theme.AppCompat.Light.DarkActionBar" and for the v21 i have it on "android:Theme.Material.Light.DarkActionBar" – Adam Nov 29 '15 at 02:33