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,
- Increase Android Emulator Timeout time
- Android : Remove ListView Separator/divider programmatically or using xml property
- Error : Invalid key hash.The key hash does not match any stored key hashes
- How to Change Android Toast Position?
- Android Alert Dialog with Checkboxes example
- Android : No Launcher activity found! Error
- Android Development: Spinners with Example
- Failed to sync Gradle project Error:failed to find target android-23
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Disable Fading Edges Scroll Effect Android Views
- How to create Toast messages in Android?
- Channel 50 SMSes received every few minutes Android Phones
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Create Custom Android AlertDialog
- How To Disable Landscape Mode in Android Application
- Android Development - How to switch between two Activities
- incorrect line ending: found carriage return (\r) without corresponding newline (\n)
- Generate Facebook Android SDK keyhash using java code
- Android Error Generating Final Archive - Debug Certificate Expired
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android RatingBar Example
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager
- fill_parent vs match_parent vs wrap_content
- Android : Connection with adb was interrupted 0 attempts have been made to reconnect
More Posts:
- How to know the current shell you are logged in? - Bash
- List of New Features in Java 11 (JEPs) - Java
- Rust: Cargo Init vs Cargo New Command - Rust
- Fix: Curl No Match Found Error - cURL
- Android Studio Change SDK Path - Android
- AWS CLI Command to Get a List of SNS Topics - AWS
- Add Bookmark macOS Safari - MacOS
- Upgrade Gradle in Android Studio - Gradle