zoukankan      html  css  js  c++  java
  • Android Studio:You need to use a Theme.AppCompat theme (or descendant) with this activity. AlertDialog

    学习《第一行代码》的时候遇到的问题。

    Process: com.example.sevenun.littledemo, PID: 2085
    java.lang.RuntimeException: Unable to start receiver com.example.sevenun.littledemo.receiver.ForceOfflineReceiver: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2426)
    at android.app.ActivityThread.access$1700(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    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:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    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.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.AppCompatDialog.setContentView(AppCompatDialog.java:80)
    at android.support.v7.app.AlertController.installContent(AlertController.java:214)
    at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:256)
    at android.app.Dialog.dispatchOnCreate(Dialog.java:361)
    at android.app.Dialog.show(Dialog.java:262)
    at com.example.sevenun.littledemo.receiver.ForceOfflineReceiver.onReceive(ForceOfflineReceiver.java:38)
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2419)
    at android.app.ActivityThread.access$1700(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1272) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5017) 
    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:779) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
    at dalvik.system.NativeStart.main(Native Method) 

    有两个解决办法:

    1. 把我们当前的Activity所继承的ActionBarActivity,改为继承Activity(android.app.Activity)。

    2.我出现错误的地方是因为使用了AlertDialog,发现我导入的android.support.v7.app.AlertDialog,然后我就改为导入android.app.AlertDialog就成功了。

  • 相关阅读:
    java 微信公众服务平台 下发 模板消息
    java web实现 忘记密码(找回密码)功能及代码
    DES加密后get获取url参数无法解密问题
    java实现url转码、解码
    java 实现 DES加密 解密算法
    oracle sqlplus 导出csv文件
    oracle导出多CSV文件的靠谱的
    Oracle 释放过度使用的Undo表空间
    Archiving not possible: No primary destinations errors
    Linux 之 shell 比较运算符
  • 原文地址:https://www.cnblogs.com/sevenun/p/5858083.html
Copyright © 2011-2022 走看看