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

    这几天想给自己的后端程序搞个前端架子,准备用安卓来实现,现学现用,直接京东搜索关于安卓的热门书籍,下个PDF搞起。

    销量第一的是《第一行代码 Android 第2版》,不错,销量第一,拿来入门应该足够了,不过这书是基于 Android 7 的,谷歌真是神速,到今天 Android 9 都已经发布了

    花了半天直接看到了第二章,虽然是安卓萌新,但也勉强实现了手机上的界面 DEMO,真刺激啊。

    先运行一下瞧瞧,先点个弹窗试试。

    根据我菜鸟般的编程经验,这不过是个小问题,后来知道了,这的确是个小问题,但这个问题也让我整整懵逼了一天。

    先贴下报错日志:

    01-03 22:38:01.430 11502-11502/com.example.activitylifecycletest E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.activitylifecycletest, PID: 11502
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activitylifecycletest/com.example.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:2416)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
            at android.app.ActivityThread.-wrap11(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103)
         Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:555)
            at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
            at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
            at com.example.activitylifecycletest.DialogActivity.onCreate(DialogActivity.java:11)
            at android.app.Activity.performCreate(Activity.java:6285)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
            at android.app.ActivityThread.-wrap11(ActivityThread.java) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:148) 
            at android.app.ActivityThread.main(ActivityThread.java:5417) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103) 
    

    You need to use a Theme.AppCompat theme (or descendant) with this activity.,瞅见了,这句话很好理解,不就是让我换个 AppCompat theme 然后继续使用嘛,小Easy。

    一开始呢,书中的代码是下面这样的:

    这尼玛完全是个坑啊,这坑在哪里呢,坑在我眼瞎啊,眼瞎啊。。。

    我改完代码之后,改成了下面这样:

    运行了一下,MMP的,这下直接给我找不到这个组件了,就是坑在这里,后来我在网上搜了很多答案,别人答案是什么样的呢?

    看见没,前面没有那个android,而我改了几十遍,都多加了个 android,这就导致我一晚上在懵逼与谷歌之中度过,为此我还翻了一堆官方文档。

    就因为自己一时眼瞎,浪费了一天时间。

    谨以此文,以示警醒。

  • 相关阅读:
    DeepIn系统使用和相关软件安装
    在JDK11中生成JRE11的方法
    IIS 7 中设置文件上传大小的方法
    在服务器上发布MVC5的应用
    安装了多个Oracle11g的客户端,哪个客户端的tnsnames.ora会起作用?
    配置putty或SecureCRT防止SSH连接中断
    借助FRP反向代理实现内网穿透
    你不知道的hostname命令
    Perl脚本通过Expect登陆多台设备批量执行命令并Log
    Linux内核参数配置
  • 原文地址:https://www.cnblogs.com/nwgdk/p/10217415.html
Copyright © 2011-2022 走看看