Aditya Mishra
Aditya Mishra

Reputation: 19

Why I can't start a new activity?

Whenever I tried to click the button it stops working.
Here are the logs:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blogspot.hlowrold.mybooks/com.blogspot.hlowrold.mybooks.Main2Activity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  at android.app.ActivityThread.access$600(ActivityThread.java:130)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:4745)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
  at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:356)
  at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325)
  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
  at com.blogspot.hlowrold.mybooks.Main2Activity.onCreate(Main2Activity.java:13)
  at android.app.Activity.performCreate(Activity.java:5008)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
  at android.app.ActivityThread.access$600(ActivityThread.java:130) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
  at android.os.Handler.dispatchMessage(Handler.java:99) 
  at android.os.Looper.loop(Looper.java:137) 
  at android.app.ActivityThread.main(ActivityThread.java:4745) 
  at java.lang.reflect.Method.invokeNative(Native Method) 
  at java.lang.reflect.Method.invoke(Method.java:511) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
  at dalvik.system.NativeStart.main(Native Method) 

What is the problem here? Please help me.

Upvotes: 0

Views: 242

Answers (3)

Rasoul Miri
Rasoul Miri

Reputation: 12222

you need add appcompat lib to build.gradle

compile 'com.android.support:appcompat-v7:25.3.1'

and add theme in styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>

and in manifest file, peresent activity this way

<activity
    android:name="YOUR_ACTIVITY"
    android:theme="@style/AppTheme" />

Upvotes: 0

Sunil P
Sunil P

Reputation: 3838

make your style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

Upvotes: 0

KnightMobile
KnightMobile

Reputation: 73

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

example styles.xml:

<style name="ThemeCompatLight" parent="Theme.AppCompat.Light.NoActionBar">
</style>

AndroidManifest.xml

<activity
        android:name=".your.activity.name"
        android:theme="@style/ThemeCompatLight" />

Upvotes: 1

Related Questions