java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
来源:互联网 发布:好听的翻唱知乎 编辑:程序博客网 时间:2024/05/21 09:21
版权声明:本文为【欧阳鹏】原创文章,欢迎转载,转载请注明出处! 【http://blog.csdn.net/ouyang_peng】
目录(?)[+]
1、错误描述
今天,想实现Activity不显示标题栏的效果,在项目的AndroidManifest.xml文件,对相应的Activity添加属性
android:theme="@android:style/Theme.NoTitleBar"
具体代码如下:
<activity android:name=".module.view.activity.KuwoMusicPlayActivity" android:theme="@android:style/Theme.NoTitleBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter></activity>
结果运行app的时候,报了如下错误:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
具体错误log如下:
01-01 01:33:41.950 6637-6637/com.xtc.kuwo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xtc.kuwo, PID: 6637 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xtc.kuwo/com.xtc.kuwo.module.view.activity.KuwoMusicPlayActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340) at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) at com.xtc.kuwo.module.view.activity.KuwoMusicPlayActivity.onCreate(KuwoMusicPlayActivity.java:57) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)? at android.app.ActivityThread.access$800(ActivityThread.java:151)? at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)? at android.os.Handler.dispatchMessage(Handler.java:102)? at android.os.Looper.loop(Looper.java:135)? at android.app.ActivityThread.main(ActivityThread.java:5254)? at java.lang.reflect.Method.invoke(Native Method)? at java.lang.reflect.Method.invoke(Method.java:372)? at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)? at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)?
如下图所示:
2、错误分析
原来我的Activity继承自 Android.support.v7.app.AppCompatActivity,而不是 android.app.Activity。
3、解决方法
方法1:
创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。
如将activity继承自AppCompatActivity:
public class MainActivity extends ActionBarActivity
改成activity继承自Activity:
public class MainActivity extends Activity
方法2:
还是想继承自AppCompatActivity,那么根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置改成:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
完整代码如下:
<activity android:name=".module.view.activity.KuwoMusicPlayActivity" 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>
问题解决!
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
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)
- 高端存储发展趋势
- HBase Filter使用介绍
- OpenGL 版本与GLSL版本
- 查看本机编码方式
- Java基础概念
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
- 使用Eclipse的Working Set,界面清爽多了
- Spring注解@Component、@Repository、@Service、@Controller区别
- 一维数组、二维数组、字符数组的&、sizeof等操作
- maven环境变量的配置及+eclipse的配置使用
- 解决CTS测试项testIsUserAMonkey
- 在iOS 8中使用UIAlertController
- iOS-iOS内购流程(手把手图文教程)
- 什么是抽象类