Caused By: Java.lang.illegalstateexception: You Need To Use A Theme-appcompat
Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upHave a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
背景: 集成环信项目,某些个别界面,打开或者启动alterDialog就会崩机,报如图说下错误 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity 原因: 1 该Acitivity继承了某些兼容Activit. It should recreate the manifest using the newer version. Then you enable all the require permissions for your sketch, if any. Not tested, but I believe I read it in the documentation not long ago.
Comments
commented Jun 30, 2017
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. |
commented Jun 30, 2017
@MissBears 插件的构建请参考:Demo 工程运行须知 |
commented Jun 30, 2017
可能你的版本比较低吧! |
commented Jun 30, 2017
我也是类似的问题 |
commented Jun 30, 2017
我也是类似的情况 |
commented Jun 30, 2017
360马上也要开源rePlugin 了,看看哪个好用就用哪个吧 |
commented Jun 30, 2017
plugindemo的BookManagerActivity是继承的AppCompatActivity,但是在manifest里面没有使用v7包的主题,把BookManagerActivity改成直接继承Activity就好了 |
Caused By Java.lang.illegalstateexception You Need To Use A Theme.appcompat Theme
commented Jun 30, 2017
我连主题都删了,都不行了啊,我用FragmentActivity的啊 |
commented Jun 30, 2017
@moziqi @xns1001@tokiii@MissBears 插件需要执行 |
referenced this issue Jul 27, 2017
ClosedUnknown element under <manifest>: #89
referenced this issue Mar 16, 2018
ClosedJNI ERROR (app bug) local reference table overflow max=512 #192
referenced this issue Nov 26, 2018
OpenJNI ERROR (app bug): local reference table overflow (max=512) #279
Android Studio 0.4.5
Android documentation for creating custom dialog boxes: http://developer.android.com/guide/topics/ui/dialogs.html
If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity>
manifest element:
However, when I tried this I get the following exception:
I am supporting the following, and I can't using something greater than 10 for the min:
In my styles I have the following:
And in my manifest I have this for the activity:
Creating the dialog box like this was something I was hopping to do, as I have already completed the layout.
Can anyone tell me how I can get around this problem?
Zoe44 Answers
The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity
which requires the AppCompat
theme to be applied.
Update: Extending AppCompatActivity
would also have this problem
In this case, change the Java inheritance from ActionBarActivity
to Activity
and leave the dialog theme in the manifest as it is, a non Theme.AppCompat
value
The general rule is that if you want your code to support older versions of Android, it should have the AppCompat
theme and the java code should extend AppCompatActivity
. If you have *an activity that doesn't need this support, such as you only care about the latest versions and features of Android, you can apply any theme to it but the java code must extend plain old Activity
.
NOTE: When change from AppCompatActivity
(or a subclass, ActionBarActivity
), to Activity
, must also change the various calls with 'support' to the corresponding call without 'support'. So, instead of getSupportFragmentManager
, call getFragmentManager
.
All you need to do is add android:theme='@style/Theme.AppCompat.Light'
to your application tag in the AndroidManifest.xml
file.
Copying answer from @MarkKeen in the comments above as I had the same problem.
I had the error stated at the top of the post and happened after I added an alert dialog. I have all the relevant style information in the manifest. My problem was cured by changing a context reference in the alert builder - I changed:
to:
And no more problems.
Pangmin sdk is 10. ActionBar
is available from api level 11. So for 10 you would be using AppCompat
from the support library for which you need to use Theme.AppCompat
or descendant of the same.
Use
Or if you dont want action bar at the top
More info @
Edit:
I might have misread op post.
Seems op wants a Dialog with a Activity Theme. So as already suggested by Bobbake4 extend Activity
instead of ActionBarActivity
.
Also have a look @ Dialog Attributes in the link below
shareefI was experiencing this problem even though my Theme was an AppCompat
Theme and my Activity was an AppCompatActivity
(or Activity
, as suggested on other's answers). So I cleaned, rebuild and rerun the project.
(Build -> Clean Project ; Build -> Rebuild Project ; Run -> Run)
It may seem dumb, but now it works great!
Just hope it helps!
This is what fixed it for me: instead of specifying the theme in manifest, I defined it in onCreate
for each activity that extends ActionBarActivity
:
Here MyAppTheme
is a descendant of Theme.AppCompat
, and is defined in xml. Note that the theme must be set before super.onCreate
and setContentView
.
In my case i have no values-v21 file in my res directory. Then i created it and added in it following codes:
Ali GürelliAli GürelliIf you need to extend ActionBarActivity you need on your style.xml:
If you set as main theme of your application as android:Theme.Material.Light instead of AppTheme.Base then you’ll get an “IllegalStateException:You need to use a Theme.AppCompat theme (or descendant) with this activity” error.
Change the theme of the desired Activity. This works for me:
I had such crash on Samsung devices even though the activity did use Theme.AppCompat.The root cause was related to weird optimizations on Samsung side:
My solution was just removing android:launchMode='singleTask'
I had the same problem, but it solved when i put this on manifest: android:theme='@style/Theme.AppCompat.
for me was solution to use ContextThemeWrapper:
from Android - How to create FAB programmatically?
In my case such issue was appear when i tried to show Dialog.The problem was in context, I've use getBaseContext() which theoretically should return Activity context, but appears its not, or it return context before any Theme applied.
So I just replaced getBaseContexts() with 'this', and now it work as expected.
Vitaliy AVitaliy AI had an activity with theme <android:theme='@android:style/Theme.Dialog'>
used for showing dialog in my appWidget and i had same problem
i solved this error by changing activity code like below:
Change your theme style parent to
This worked for me ...
FazalFazalYou have many solutions to that error.
You should use Activity or FragmentActivity instead of ActionbarActivity or AppCompatActivity
If you want use ActionbarActivity or AppCompatActivity, you should change in styles.xmlTheme.Holo.xxxx to Theme.AppCompat.Light (if necessary add to DarkActionbar)
If you don't need advanced attributes about action bar or AppCompat you don't need to use Actionbar or AppCompat.
KalogluKalogluIn Android manifest just change theme of activity to AppTheme as follow code snippet
maxhbThis is when you want a AlertDialog in a Fragment
I had this problem as well and what I did to fix it, AND still use the Holo theme was to take these steps:
first I replaced this import:
with this one:
then changed my extension from:
to this:
And also had to change this import:
to this import:
and then you can use your theme tag in the manifest at the activity level:
and lastly, (unless you have other classes in your project that has to use v7 appCompat) you can either clean and rebuild your project or delete this entry in the gradle build file at the app level:
if you have other classes in your project that has to use v7 appCompat then just clean and rebuild the project.
You have came to this because you want to apply Material Design in your theme style in previous sdk versions to 21. ActionBarActivity
requires AppTheme
so if you also want to prevent your own customization about your AppTheme, only you have to change in your styles.xml (previous to sdk 21) so this way, can inherit for an App Compat theme.
for this:
danigonlineadanigonlineaYour Activity is extending ActionBarActivity which requires the AppCompat.theme to be applied.Change from ActionBarActivity to Activity or FragmentActivity, it will solve the problem.
If you use no Action bar then :
Md Imran ChoudhuryMd Imran ChoudhuryIn my experiences the problem was the context where I showed my dialog.Inside a button click I instantiate an AlertDialog in this way:
But the context was not correct and caused the error. I've changed it using the application context in this way:
In declare section:
in the onCreate method
And finally in the code where I need the AlertDialog:
This is the solution for me.
Quick solution.
Change your base theme parent in styles.xml
Replace from
to
KalogluKalogluThis solution worked for me.
Design library depends on the Support v4 and AppCompat Support Libraries, so don't use different version for appcompat and design library in gradle.
use
instead of
kiran boghrakiran boghraI was getting this same problem. Because i was creating custom navigation drawer. But i forget to mention theme in my manifest like this
android:theme='@style/Theme.AppCompat.NoActionBar'
As soon i added the above the theme to my manifest it resolved the problem.
For me none of the above answers worked even after I had Theme.AppCompat
as my base theme for the application. I was using com.android.support:design:24.1.0
So I just changed the version to 24.1.1
. After the gradle sync, Its working again and the exception went away. Seems to me the issue was with some older versions of design support libraries.
Just putting this here in case other answers don't work for some people.
Sharp EdgeSharp Edgeprotected by Community♦Apr 2 '16 at 21:18
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?