【我的Android进阶之旅】解决bug:You need to use a Theme.AppCompat theme (or descendant) with this activity.
来源:互联网 发布:mindjet mac 破解教程 编辑:程序博客网 时间:2024/06/07 13:12
前言
今天用Android Studio 生成Activity的时候,默认继承AppCompatActivity ,而在AndroidManifest.xml我对该Activity设置了一个主题,然后运行的时候报了错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xtc.watch/com.xtc.watch.view.defaultprompt.activity.DefaultPromptActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
如下所示:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xtc.watch/com.xtc.watch.view.defaultprompt.activity.DefaultPromptActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2729) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1576) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5905) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124) at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59) at com.xtc.watch.view.defaultprompt.activity.DefaultPromptActivity.onCreate(DefaultPromptActivity.java:30) at android.app.Activity.performCreate(Activity.java:6298) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2729) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1576) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5905) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
AndroidManifest.xml文件中关于该Activity的配置如下:
<activity android:name=".view.defaultprompt.activity.DefaultPromptActivity" android:theme="@style/dialog_watch_upgrade_style"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>
而DefaultPromptActivity继承于AppCompatActivity ,如下代码所示:
public class DefaultPromptActivity extends AppCompatActivity {
解决方法
我这里就无意中继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。
所以就要使用与其配合的AppCompat的theme才行,将DefaultPromptActivity改为继承于Activity ,如下代码所示:
public class DefaultPromptActivity extends Activity {
这个bug就解决了。
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/52749732
- 【我的Android进阶之旅】解决bug:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 我的Android进阶之旅------>解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android 解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android错误之:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决
- 【已解决】You need to use a Theme.AppCompat theme (or descendant) with this activity
- You need to use a Theme.AppCompat theme (or descendant) with this activity错误解决
- 解决You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android开发~you need to use a theme.appcompat theme (or descendant) with this activity
- 【Android】You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android Studio You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android Studio中报错 You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android问题一:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android--You need to use a Theme.AppCompat theme (or descendant) with this activity解决方案
- Android异常-You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android Studio: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android issue: You need to use a Theme.AppCompat theme (or descendant) with this activity
- iOS开发笔记之五十四——App减肥常用方法
- Ajax探究
- web开发---为什么要安装web服务器
- 教你轻松自定义ViewPagerIndicator
- photoshop 永久使用,破解
- 【我的Android进阶之旅】解决bug:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- git克隆远程项目时注意问题!!!
- 关于一些业务逻辑的处理技巧
- JAVA多线程的总结和代理模式理解
- kindeditor4.x整合SyntaxHighlighter代码高亮
- 获取CTreeCtrl所有结点的附加数据(ItemData)
- Android-ViewPagerIndicator简单集成
- Unity3D自带Mouse Look鼠标视角代码解析。
- KOOCAN教你如何用一句话毁掉优质电影