java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
来源:互联网 发布:sublime php 语法检查 编辑:程序博客网 时间:2024/06/06 00:01
在实际项目中遇到了标题的问题,java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 报错的信息是这样的,启动页启动不了,直接闪退了。主要是因为现在导入了v7包。
根据报错信息,找到了配置清单文件,修改如下。
<application android:name="com.hipad.news.app.AppApplication" android:allowBackup="true" android:icon="@drawable/icon_n" android:label="@string/app_name" android:theme="@style/Theme.AppCompat" > <activity android:name="com.hipad.news.activity.Welcome" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
将启动的theme修改为v7包下的主题
android:theme="@style/Theme.AppCompat"然后在启动页的配置中添加theme
android:theme="@style/Theme.AppCompat.Light.NoActionBar"就可以了。
后来查找一些资料,如下:
,想实现Activity不显示标题栏的效果,在项目的AndroidManifest.xml文件,对相应的Activity添加属性
- 1
- 1
具体代码如下:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
结果运行app的时候,报了如下错误:
- 1
- 1
具体错误log如下:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
如下图所示:
2、错误分析
原来我的Activity继承自 Android.support.v7.app.AppCompatActivity,而不是 android.app.Activity。
3、解决方法
方法1:
创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。
如将activity继承自AppCompatActivity:
- 1
- 1
改成activity继承自Activity:
- 1
- 1
方法2:
还是想继承自AppCompatActivity,那么根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置改成:
- 1
- 1
完整代码如下:
0 0
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this
- 异常IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- eclipse:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) wit
- Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant)
- Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant)
- Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant)
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant
- Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant)
- Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant)
- 认识registerActivityLifecycleCallbacks
- MySQL学习过程
- 记录学习的点滴(MyBatis中插入操作返回主键)
- 截取页面链接url参数的方法
- SYS与SYSTEM、DBA与SYSDBA的区别
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- 如何使用外部的数据库文件
- Ubuntu 安装WPS office 2016
- 深入理解javascript原型和闭包(12)——简介【作用域】
- 学java需掌握的面试基础……?
- iOS UIKit框架详解
- C# 第三章单测
- Arrays类中Arrays.asList()方法
- 在安装VS2010的windows环境下搭建QT开发环境