You need to use a Theme.AppCompat theme (or descendant) with this activity.
来源:互联网 发布:伊顿穆勒编程软件 编辑:程序博客网 时间:2024/06/10 21:16
《Android第一行代码》2.4.3 Activitylifecylcetest代码运行时错误错误形式:点击按钮start dialog时程序停止运行
控制台输出:
08-30 20:44:57.532 1542-1542/com.example.sf.activitylifecycletest E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.sf.activitylifecycletest, PID: 1542 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sf.activitylifecycletest/com.example.sf.activitylifecycletest.DialogActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5324) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 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.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:356) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at com.example.sf.activitylifecycletest.DialogActivity.onCreate(DialogActivity.java:11) at android.app.Activity.performCreate(Activity.java:5343) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5324) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) at dalvik.system.NativeStart.main(Native Method)
关键句:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sf.activitylifecycletest/com.example.sf.activitylifecycletest.DialogActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
错误原因:
出现错误的原因是你试图加载的活动继承了ActionBarActivity或者AppCompatActivity类,而这两个类要求必须使用AppCompat主题
解决方法:
将继承的类由上述两个类改为Activity类即可,其它部分不用做更改。
更过信息可以参考:
https://stackoverflow.com/questions/21814825
阅读全文
0 0
- 关于“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解决方法
- 【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.
- 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 Studio 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解决方法
- 古文觀止卷八_祭十二郎文_韓愈
- MOOC清华《面向对象程序设计》第5章:OOP版电子计价器
- LightOJ-1042---Secret Origins (贪心+暴力)
- jpa学习笔记——2
- PHP-约瑟夫环
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 编写优质嵌入式C程序
- 为什么python性能差
- ECMAScript6(ES6)
- 设计模式-观察者设计模式
- 如何用jquery获取input输入框中的值?
- MFC学习日志(一)
- LFU缓存策略
- PHP -单例模式 -简单工厂-抽象工厂