使用adt开发新建一个Android app,选择支持的SDK版本如果小于11(Android3.0)就会报如下错误。

error: Error retrieving parent for item: No resource found that matches the given name ‘Theme.AppCompat.Light’.

官网给出的答案是:

https://developer.android.com/tools/support-library/setup.html#add-library

简单来说就是新的eclipse默认模版主题UI需要使用比较高版本api,如果需要支持低版本,需要导入appCompact库来支持,网上一般给出的解法:

File->Import (android-sdk\extras\android\support\v7). Choose “appcompat”
Project-> properties->Android. In the section library “Add” and choose “appCompat”
包括stackoverflow上也有很多人遇到,但很多人通过这个解决,但我就是没办法解决。

后来发现这个是eclipse的bug,如果你引用的库和你的代码不在一个盘符,就有此异常。
我的代码在E盘,appCompact的库在D盘,我从新将其移动到E盘就ok。
fuck,浪费好多时间。
有遇到同样问题的可参考。

//------------------------------------------------------------------------------------------------------------------------------------------------

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.example.test2.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

解决方法:
创建的activity是MainActivity extends ActionBarActivity这样的。把后面的ActionBarActivity改成Activity,然后导包,把下面报错的地方删掉运行就不报错了。。。

//------------------------------------------------------------------------------------------------------------------------------------------------

Android问题集锦之二十八:You need to use a Theme.AppCompat theme (or descendant) with this activity.
分类: Android2015-01-13 17:49 1694人阅读 评论(0) 收藏 举报
错误描述为:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

起因:
我想在Manifest中设置我的activity全屏,代码如下:
[html] view plaincopy在CODE上查看代码片派生到我的代码片

原因:
从错误提示中提到Theme.AppCompat theme,这是因为我们的activity一定是继承了兼容包中的类,
比如我这里就无意中继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。
所以就要使用与其配合的AppCompat的theme才行。

解决:
1.根据提示来使用AppCompat的theme,如下:
[html] view plaincopy在CODE上查看代码片派生到我的代码片


不过我要设置全屏,但我并没有找到,所以虽然错误不见了,但并没有达到我的预期。

2.如果不是那么强烈需要继承自ActionBarActivity,就直接继承Activity吧。问题自然搞定!

猜你喜欢

转载自blog.csdn.net/weixin_44146252/article/details/85082264