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。

Android:真机调试遇到的问题(You need to use a Theme.AppCompat theme (or descendant) with this activity)的更多相关文章

  1. 在Mac系统上配置Android真机调试环境

    在Mac系统上配置Android真机调试环境 mac上配置安卓环境还说挺方便的,真机调试也比win上要好一些.win上被各种软件强行安装了xxx助手. 在mac上就了一个干净的感觉. 下载Androi ...

  2. Unity Profiler连接Android真机调试

    Profiler在Editor模式就可以观看性能消耗,但是毕竟电脑配置高,跟手机真机环境还是有区别.实际开发中的优化还是推荐用真机测试. 因为IOS一般比Android手机的配置高,在Android平 ...

  3. Android真机调试手动添加程序包的LogCat

    android真机调试有时候看LogCat 时,有时候那个跑的本程序的LogCat 没有出现而是 出现的是" All messages (no filters) " .此时 的Lo ...

  4. Unity Frame Debugger连接Android真机调试

    当用Profiler分析到不是代码导致的性能问题,当前场景最大的性能瓶颈是渲染时,或者自己写的Shader要调试时,都可以用Frame Debugger进行调试. 按下列步骤设置打包,既可以用Prof ...

  5. Android真机调试试验

    之前一直使用模拟器,很不好用,今天使用真机调试试验. 准备材料:电脑,Android手机. 首先,就遇到了一个问题,我的手机是华为的,之前不知道怎么回事,打开调试总是自动关闭,而且切换总是切换不了,老 ...

  6. Android ——真机调试

    1. 设置android手机为USB调试模式.步骤: menu---> 设置 ---> 应用程序 ---> 开发 , 选择[USB调试] 2. 用USB连接手机和电脑,并确保成功.步 ...

  7. eros --- Windows Android真机调试

    1.下载并安装JDK 2.下载并安装Android Studio 上面两项不管用weex还是eros都是前置条件,度娘有大量教程. 开始eros 手脚架安装: $ npm i -g eros-cli ...

  8. Android真机调试访问本地服务器(localhost)的解决方案

    Android系统把它自己作为了localhost!当连接localhost都是他自己啊.. 囧,在这里晕了好久才发现.. 网上介绍的都是模拟器连接本地服务器的,我试着把链接改为http://10.0 ...

  9. Android真机调试的时候logcat中无法输出调试信息的解决办法

    真机调试不输出日志到logcat的原因是手机厂商默认关闭了调试打印的功能,通过以下方法开启此方法. 下面以华为P6手机为例进行操作: 1.在拨号界面输入:*#*#2846579#*#* 进入测试菜单界 ...

  10. android 真机调试出现错误 INSTALL_FAILED_INSUFFICIENT_STORAGE 的解决方法。

    关于这个神奇的 内存不够错误的通常解决方法,网上大把,建议大家在尝试过了网上的方法后再来尝试下我的这种方法. 编译工具: android studio 测试真机:米 2 调试的时候出现:INSTALL ...

随机推荐

  1. 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同

    思路:利用&用算加右移的方法来提取二进制中的每一位数,然后进行比较,查看是否相同. #include<stdio.h> #include<stdlib.h> int m ...

  2. 非递归和递归分别实现求第n个斐波那契数。

    菲波那切数列为:0 1 1 2 3 5 8 13 21 34... 规律:从第三个数字起后面的每一个数字都是前两个数字的和. 非递归算法: #include<stdio.h> int ma ...

  3. RTSP为什么VLC播放器无法播放

    rtsp_tracepoint: rtspservice.c,RTSP_state_machine, state_machine:current state is ready state curren ...

  4. Python之安装pip

    安装Python之后,命令行语句定位到其安装目录下的Scripts目录 如我的安装目录是:D:\python\Scripts 然后执行命令:easy_install.exe pip就会开始安装pip ...

  5. FastAdmin Git 开发更新流程

    更加简洁的流程 FastAdmin 使用 Git 更新的新用法 https://www.cnblogs.com/F4NNIU/p/9120365.html

  6. MySQL锁机制&&PHP锁机制,应用在哪些场景中呢?

    正文内容 模拟准备--如何模拟高并发访问一个脚本:apache安装文件的bin/ab.exe可以模拟并发量 -c 模拟多少并发量 -n 一共请求多少次 http://请求的脚本 C:\phpStudy ...

  7. STM32的SPI2操作Flash

    关于STM32F107的SPI标志 SPI_I2S_FLAG_BSY和SPI_I2S_FLAG_TXE的疑问  http://www.openedv.com/posts/list/23579.htm ...

  8. Elasticsearch的脚本化数据导入导出

    我用的ES的版本是2.4.1,由于没有相应的命令实现数据的导入和导出,就是像mysql的那种mysqldump类似的指令. 更苦逼的是,我们的生产和测试环境,还不能联网,连ES的第三方的插件都没有办法 ...

  9. linux进程监控和简单的重启&服务的创建 参考自http://blog.csdn.net/lockheed_hong/article/details/73549837

    脚本文件 该脚本实现了一个检测进程是否存在,不存在的情况下重启进程并且记录日志. #! /bin/sh proc_name="console/queue/gift.php" # 进 ...

  10. Comparator 排序 ArrayList 实操练习

    package ltb6w; import java.util.Scanner;import java.util.ArrayList;import java.util.Comparator;impor ...