Recently I ran into java.lang.IllegalStateException with an error message saying You need to use a Theme.AppCompat theme (or descendant) with this activity.
Error Stacktrace:
11-17 11:37:59.239: E/AndroidRuntime(7852): FATAL EXCEPTION: main
11-17 11:37:59.239: E/AndroidRuntime(7852): java.lang.RuntimeException:
Unable to start activity ComponentInfo
{ com.code2care.example.abc/com.code2care.example.abc.Details }:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.
run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
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.ActionBarActivityDelegate.
onCreate(ActionBarActivityDelegate.java:147)
at android.support.v7.app.ActionBarActivityDelegateBase.
onCreate(ActionBarActivityDelegateBase.java:139)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.code2care.example.abc.Details.onCreate(Details.java:24)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
I have an Activity A which on a button click displays an Activity B on dialog, and the theme I have applied for Activity B is android:theme = "@android:style/Theme.Dialog".
The reason for this error is that the Activity B java file extends class ActionBarActivity which requires themes from AppCompat whereas we have used a theme from Theme.Dialog
SolutionJust change the Activity that is displayed as a Dialog extends class to Activity instead of ActionBarActivity
More Posts related to Android,
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Android Emulator cannot be opened because the developer cannot be verified. [M1 Mac]
- How to Change Android Toast Position?
- Fail to connect to camera service Android java RuntimeException
- How to create Custom RatingBar Android Programming Tutorial
- Fixing Android unknown error 961 while downloading app
- Android AlertDialog with Yes No and Cancel Button
- Share or Send SMS via Android Intent
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Pass data between two Android Activities and access it using Intent
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android EditText Cursor Colour appears to be white
- Android Development - How to switch between two Activities
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Android : Remove ListView Separator/divider programmatically or using xml property
- Android is starting optimizing... app 1 of 1
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- AlertDialog with single button example : Android
- Android : Exception raised during rendering: action_bar API 22
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Center align text in TextView Android Programming
- How to Download and Install Android adb Tool on Linux, Mac or Windows
- Multiline EditText in Android Example
More Posts:
- Failed to sync Gradle project Error:failed to find target android-23 - Android
- Calculate Area of Trapezoid - C-Program
- How to reset Mac Password using Terminal - MacOS
- Run Scripting Language (JavaScript, Python, Groovy, Ruby) in Java - Java
- Create a large dummy file using Mac OS X terminal command - Mac-OS-X
- How to Install glib on Mac - MacOS
- Change CKEditor Table Properties default width - CKEditor
- Step-by-Step: How to delete a git branch from local as well as remote origin - Git