症状:

1、控制台报错:

[2015-02-13 13:47:05 - GodHand2] D:\Workspace\godhand\appcompat_v7\res\values-v21\styles_base.xml:75: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.
[2015-02-13 13:47:05 - GodHand2] 
[2015-02-13 13:47:05 - GodHand2] D:\Workspace\godhand\appcompat_v7\res\values-v21\styles_base.xml:79: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton.CloseMode'.

.........等等都是
Error retrieving parent for item: No resource found that matches the given name ‘.......’ 这种格式的
2、R.java 文件不见 src中有R.findViewById() 3、values中的values-21报错 打开出现这种情况,其中红叉的报错是: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.




本人两次遇到这种情况:

情况一:新生成生成一个Android Application Project 的时候

情况二:手贱删除了项目列表里一个创建项目时自动生成  appcompat_v7  项目。


总结的解决办法:

情况一:按照   http://jingyan.baidu.com/article/bea41d439bd6d5b4c41be659.html   中说的办法完成就可以解决

情况二:本来按照情况一的办法解决,可是按照 项目右键——属性——Android——Add 完 appcompat-v7 后下次打开又导入失败


1、把appcompat-v7 项目删除,不要勾选磁盘删除!

2、导入C:\Program Files\Android\extras\android\support\v7\appcompat

在出现如下一步的时候把钩打上(解决上述的导入失败)


3、导入后的v7 项目是报错的如下


4、打开v7 即上图中的 project.properties 把target=android-19 改成 target=android-21,clean下即刻发现错误消失。

5、右键你原来的项目——属性——Android——Add   appcompat-v7  导入成功


以上就是情况二与情况一的区别

6、clean一下,你会发现R.java文件已经出来了

extras:

7、如果你发现有的 .java 文件的R.layout.xx 语句还在报错,查看你的 import 语句看看是否存在

import android.R;

把它删掉,保持下就可以了。


==============================================================================

附录一:

以前3.0以前的版本要使用ActionBar,必须使用国外大牛写的ActionBarSherlock这个开源项目。今年的Google/IO大会之后,Google官方在android-support-v7包中添加了ActionBar,开始让2.1以后的版本支持ActionBar,从此以后曾经最火的Android开源项目ActionBarSherlock可以退出历史舞台了。


要是用V7包中ActionBar也很简单,但有一个需要注意的地方。有些人可能刚开始仅仅是把android-support-v7-appcompat.jar导入项目中,但是在设置Activity的theme时会报错,提示找不到"@style/Theme.AppCompat"。这是由于我们要把v7和资源文件一起导入才行。

具体使用步骤(针对于Eclipse):

Create a library project based on the support library code:

  1. Make sure you have downloaded the Android Support Library using the SDK Manager.
  2. Create a library project and ensure the required JAR files are included in the project's build path:
    1. Select File > Import.
    2. Select Existing Android Code Into Workspace and click Next.
    3. Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding theappcompat project, browse to /extras/android/support/v7/appcompat/.
    4. Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    5. In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar andandroid-support-v7-appcompat.jar files to the build path.
    6. Right-click the project and select Build Path > Configure Build Path.
    7. In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
    8. Uncheck Android Dependencies.
    9. Click OK to complete the changes.

You now have a library project for your selected Support Library that you can use with one or more application projects.

Add the library to your application project:

  1. In the Project Explorer, right-click your project and select Properties.
  2. In the Library pane, click Add.
  3. Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
  4. In the properties window, click OK.

Once your project is set up with the support library, here's how to add the action bar:

  1. Create your activity by extending ActionBarActivity.
  2. Use (or extend) one of the Theme.AppCompat themes for your activity. For example:
     android:theme="@style/Theme.AppCompat.Light" ... >

Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.

On API level 11 or higher

The action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or higher. If you don't want the action bar for an activity, set the activity theme to Theme.Holo.NoActionBar.

================================================================================================================= 附录二: http://blog.csdn.net/lvge5574/article/details/38921965

项目经常需要引用别人的library工程,在选项中add进来后,点击应用或者确定,关闭页面。

回到代码中却发现无法链接,重新打开properties查看,发现导入的工程总是提示红色,add失败的样子。


原因:

这种情况,主要是因为两个android工程不在同一目录下,不属于同一盘符的文件夹里。

解决:

1.分别查看工程所在路径,放到一起,然后重新add,刷新即OK。

2.在import外部工程时,可以在Import Projects界面勾选上Copy projects into workspace,

   这样系统会copy一份到当前的目录,也不会出现连接不上的情况


PS:有些人说自身工程的target sdk version需要与外部library保持一致或者更高,通过实验,发现与这一点的设定无关。

===========================================================================================

附录三:http://jingyan.baidu.com/article/bea41d439bd6d5b4c41be659.html


当我们开发android应用需要用到android-support-v7-appcompat.jar这个库时(比方说要在2.2版本上使用actionbar和fragment),在项目中导入v4和v7这两个库之后,新手往往会遇到一些问题。在这里,总结一下可能遇到的问题,以及解决的方法。


工具/原料

需要两个库:android-support-v4.jar,android-support-v7-appcompat.jar

温馨提示:这两个库最好版本一样,否则可能会有一些其他问题产生。

这两个库可以从sdk下的sdk\extras\android\support中获取

方法/步骤

首先是在项目中导入这两个库

可以通过在项目根目录创建一个libs文件,然后把这两个库拷贝到里面,然后eclipse刷新一下这个项目,eclipse会智能添加这两个库

Android项目使用support v7时遇到的各种问题

添加完之后,可能遇到的问题:

一类问题:  

values\......No resourcefound

比方说:

res\values\styles.xml:4: error: Errorretrieving parent for item: No resource found that matches the given name'Theme.AppCompat.Light.DarkActionBar'.

对于values这个地方产生的no resource found问题,说明是没有v7下的资源。

解决方法:

添加资源库,针对上面的例子,AppCompat这个是v7里的,所以缺少的是v7的资源。从sdk去获取,路径是sdk\extras\android\support\v7\appcompat,把这个library通过eclipse导入(import)。然后之前的项目添加该lib,再clean下。这样上面的问题可以搞定。

Android项目使用support v7时遇到的各种问题

Android项目使用support v7时遇到的各种问题


二类问题:

values-v11,values-v21,values-v17等等下的No resource found

比方说:

appcompat\res\values-v21\styles_base.xml:75:error: Error retrieving parent for item: No resource found that matches thegiven name 'android:Widget.Material.ActionButton'.

appcompat\res\values-v11\themes_base.xml:178:error: Error: No resource found that matches the given name: attr'android:windowActionBar'.

appcompat\res\values-v14\themes_base.xml:27:error: Error: No resource found that matches the given name: attr'android:actionModePasteDrawable'.

对于在values-v11这类针对不同android target加载的values下找不到资源的问题,原因还是一样,找不到这个target下的资源。

解决方法:

很简单,把project.properties里的target=android-8或者可能稍微高点,改到target=android-21或者更高(前提是sdk已经下载了该target的库),然后再clean下项目。这样这类问题也就解决了,当然你在Manifest里不要忘记加上uses-sdk,来允许最低版本。

4、最后附上测试写的actionbar tab加上fragment,在Android2.3.4三星手机上的实现结果


更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
  3. Android.mk加入aidl编译
  4. 使用ant自动化构建android项目
  5. magicIndicator使用简记
  6. Android(安卓)Studio:Github Error:Could not read from remote
  7. Fresco对Eclipse的支持以及使用教程
  8. Android软键盘确认键执行两次
  9. 使用Android(安卓)Stdio出现':app:transformClassesWithDexForDe

随机推荐

  1. c语言中将一个字符串转换到整型数据类型
  2. c语言整除符号是什么?
  3. c语言\n什么意思?
  4. C语言中数据int的取值范围为多少?
  5. sqrt在c语言中怎么用?
  6. C语言中如何生成1~100的随机数(附代码)
  7. vc++6.0怎么调试?
  8. c语言中pow函数的用法是什么?
  9. c语言用户标识符命名规则是什么?
  10. c语言中if(x)是什么意思?