Android:真机调试遇到的问题(You need to use a Theme.AppCompat theme (or descendant) with this activity)。

在调试《第一行代码》这本书上的代码时,遇到了一个问题,有一个问题是想在一个活动中打开一个对话框,我按照书中的代码敲上去出了错。

我的机子是红米note,android版本是4.4.4。

错误是报:

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

书上源码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cailu.activitylifecycletest"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NormalActivity" />
<activity android:name=".DialogActivity"
android:theme="@android:style/Theme.Dialog"></activity>
</application> </manifest>

我改为下面这样就好了:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cailu.activitylifecycletest"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NormalActivity" />
<activity android:name=".DialogActivity"
android:theme="@style/Theme.AppCompat.Dialog"></activity>
</application> </manifest>

那么根本原因是什么呢?查看日志,发现:

On devices with API level below 21, a full build is required if the app is not running.
dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering

其实,出现以上情况,是因为代码所调用的一些方法只能在较高的API level上使用,而调试用的机子或模拟器所用的SDK Version小于该API level。

最新文章

  1. 使用Connetion的属性RetainSameConnection
  2. metro压缩和解压文件
  3. ios 7.1.2 拍照声音
  4. Codeforces 447 C DZY Loves Sequences【DP】
  5. Android.9图片评论(一个)
  6. 移动端 web开发心得
  7. USACO 3.2 Contact
  8. 【WebApi系列】浅谈HTTP
  9. 完全卸载删除gitlab
  10. 利用jQuery如何获取当前被点击的按钮
  11. Mysql+Keepalived双主热备高可用操作记录
  12. javascript中6种基本数据类型详解
  13. 【洛谷p1507】NASA的食物计划
  14. asp.net之发送邮件2
  15. POJ 2491
  16. java中的String类的不可变性的小例子
  17. 【转】一件有趣的事:我用 Python 爬了爬自己的微信朋友
  18. Salt-ssh批量自动安装被控端salt-mini
  19. CSS3组件化之菊花loading
  20. Mybatis日期类型的关系判断

热门文章

  1. MySQL管理实务处理
  2. python之路---12 生成器 推导式
  3. Java 笔试题(一)
  4. Spring Cloud(Dalston.SR5)--Eureka 服务提供者
  5. 自动加载以及Composer的实现
  6. 关于java的一些小知识(课程作业01)
  7. Windows核心编程 中部分代码 Delphi 实现
  8. Debian下Netbeans编辑器字体锯齿现象
  9. 自定义Write节点的beforerender属性
  10. [InfluxDB] 安装与配置