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
- Android Error Unexpected cast to Button: layout tag was FrameLayout
- ADT quit unexpectedly error on Mac OSX Android Eclipse SDK
- Parsing Data for android-21 failed unsupported major.minor version 51.0
- Android Studio Ctrl Shift o auto import not working
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android : How to make TextView Scrollable
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Integrating Android Facebook SDK 3.17.2 Tutorial
- Android R Cannot Be Resolved To A Variable
- Android : Exception raised during rendering: action_bar API 22
- How to take screenshot on Android
- Read Text file from SD Card : Android Programming
- How to make Android EditText not editable
- Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.
- The declared package does not match the expected package Eclipse
- Can't Run SDK Manager find_java.bat issue
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations
- Android Emulator Soft Back button action using Computer keyboard
- Multiline EditText in Android Example
- Use 5G Network on Android Emulator
- Make Android TextView Clickable like Buttons
- How to empty trash in Android Device
- Android : Execute some code after back button is pressed
- Disable Fading Edges Scroll Effect Android Views
- How To Disable Landscape Mode in Android Application
- Fix Power Automate FLOW error - InvalidTemplate Unable to process template language expressions in action - Microsoft
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations - Android
- Clone Bitbucket repo in VS Code - HowTos
- Android Installation error: INSTALL_FAILED_OLDER_SDK on Device - Android
- How to enable Do Not Disturb (DND) mode in Microsoft Teams - Teams
- Java code to check Internet Connection on Android Device Programmatically - Android
- How to hide lines in Notepad++ - NotepadPlusPlus
- Format Code in Visual Studio - VS Code [Mac/Windows/Linux] - HowTos