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问题
https://blog.csdn.net/jyw935478490/article/details/72868751
按照官网写的第一个APP,出现了You need to use a Theme.AppCompat theme (or descendant) with this activity问题
这是我第一次根据Android官网指导写的APP,链接如下:
每一步都严格参照了官网指导,一步一步敲代码、运行,结果报了如下错误:
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at com.huawei.anrdemo.DisplayMessageActivity.onCreate(DisplayMessageActivity.java:13)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7372)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
- 10-08 18:08:40.878 18503 18503 E AndroidRuntime: ... 9 more
本地环境: Android Studio 3.0.1版本,APP 的 Gradle version是4.1,Android Plugin Version是3.0.1,Compile SDK Version是API 26,Min SDK Version是21,Target SDK Version是API 26,其余参数都是默认。
首先,这个问题我没有Google,也没有去百度查,只从其报错上思考了下,意思是说你的这个activity需要使用一个Theme.AppCompat主题或descendant(没有去查这个descendant是什么意思)
既然不懂descendant是什么意思,那姑且就尝试下 Theme.AppCompat 吧
由于官网定义的这个 DisplayMessageActivity 继承的是 AppCompatActivity,然后我就尝试在 AndroidManifest.xml 里面将 DisplayMessageActivity 的定义增加了一个属性 android:theme="@style/Theme.AppCompat",重新运行后果然成功。于是自己得出这个结论:
如果 activity 继承的是 AppCompatActivity,那么它在 AndroidManifest.xml 里面需要设置一个 Theme.AppCompat 主题。
那如果 activity 不继承 AppCompatActivity 呢,然后我又把 DisplayMessageActivity 的定义改成了 extends Activity,并把AndroidManifest里面的 Theme.AppCompat 去掉,同样可以正常运行。
奇怪的是,明明按照官网一步一步敲的代码,为什么官网没有指出这里的问题?
如果知道这个原因的大神,还请留言讨论,谢谢。
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.
学习 Activity 生命周期时希望通过 Dialog 主题测试 onPause() 和 onStop() 的区别,点击按钮跳转 Activity 时报错: E/AndroidRuntime: FA ...
- Android You need to use a Theme.AppCompat theme (or descendant) with this activity.
错误描述为:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with ...
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.exampl ...
- You need to use a Theme.AppCompat theme
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dji.sdk.sample/com.dji.sdk.sa ...
- java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with this activity
错误描述:java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with t ...
- 关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法
android的一个小问题: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme ( ...
- 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.RuntimeExcepti ...
- 开发中遇到的问题(一)——java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
1.错误描述: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) wit ...
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme
配置: 中设置theme为 <application android:allowBackup="true" android:icon="@mipmap/ic_lau ...
- Android Studio: You need to use a Theme.AppCompat theme (or descendant) with this activity.
错误描述为: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with ...
随机推荐
- Linux enca命令
一.简介 enca是Linux下的文件编码转换工具. 二.安装 http://dl.cihar.com/enca/ http://www.2cto.com/os/201404/295528.htm ...
- centos7 dubbokeeper安装
下载dubbokeeper源码 git clone https://github.com/dubboclub/dubbokeeper mysql 先执行install-mysql.sh 编译好 ...
- PV对第三方存储的访问模式支持
访问模式 PV可以使用存储资源提供商支持的任何方法来映射到host中.如下的表格中所示,提供商有着不同的功能,每个PV的访问模式被设置为卷支持的指定模式.比如,NFS可以支持多个读/写的客户端,但可以 ...
- Linux下javaweb环境搭建
步骤: 1.使用远程工具连接上服务器,例如xsheel(ssh).filezilla(ftp) 2.JDK安装及相关配置 3.Mysql安装及相关配置 4.Tomcat安装及相关配置 5.项目部署及启 ...
- ZOJ3768 Continuous Login 2017-04-14 12:47 45人阅读 评论(0) 收藏
Continuous Login Time Limit: 2 Seconds Memory Limit: 131072 KB Special Judge Pierre is rec ...
- handsontable-developer guide-data binding,data sources
数据绑定: 1.表格中得数据是引用了数据源中的数据:表格中数据改变,数据源中得数据也改变:数据源中得数据改变,通过render方法,表格中的数据也改变: 2.如果想把数据源中的数据和表格中的数据分开: ...
- Sharepoint安装的几处注意事项
0.sharepoint自带组件安装,无需另下载安装 1.必须安装域(不安装会提示sharepoint 指定的用户是本地账户) 2.域安装后需要在sharepoint设置的数据库账号具有域权限及高级权 ...
- Linux Redis 开机启动
通过初始化脚本启动Redis 在Redis源代码目录的utils文件夹中有一个名为redis_init_script的初始化脚本文件.需要配置Redis的运行方式和持久化文件.日志文件的存储位置.步骤 ...
- solr特点二:Facet(1)
一. Facet 简介 Facet 是 solr 的高级搜索功能之一 , 可以给用户提供更友好的搜索体验 . 在搜索关键字的同时 , 能够按照 Facet 的字段进行分组并统计 . 二. Fa ...
- AngularJs2 构建简单的英雄编辑器
参考上一篇文章的步骤,重新把相关环境准备.目录结构走一遍. 这一次我们要开始创建真正的Angularjs项目了. 显示我们的英雄 我们要在应用中显示英雄数据 我们来为 AppComponent 添加两 ...