简体   繁体   English

修复styles.xml中的错误以生成R.java:找不到资源名称'Theme.AppCompat.Light'

[英]Fixing Error in styles.xml to generate R.java : No resource found name 'Theme.AppCompat.Light'

I am new to Android and am trying to run my first program. 我是Android新手,我正在尝试运行我的第一个程序。 However, based on my searches across the internet, I think that I can't import mypackage.R because r.java has not been generated because of errors in my style.xml files. 但是,基于我在互联网上的搜索,我认为我无法导入mypackage.R因为我的style.xml文件中的错误尚未生成r.java I have searched around trying to figure out how to fix these but I can't find a fix that works. 我一直在寻找如何解决这些问题,但我找不到一个有效的修复方法。 The error in styles.xml is styles.xml的错误是

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

Does anyone know how to fix this? 有谁知道如何解决这一问题?

![Errors in style.txt][1] ![style.txt中的错误] [1]

Here is the code I am using: 这是我正在使用的代码:

package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}

UPDATE: Here is styles.xml: 更新:这是styles.xml:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>

UPDATE 2: Here is AndroidManifest.xml 更新2:这是AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

You are trying to use Theme.AppCompat.Light theme which is a library project. 您正在尝试使用Theme.AppCompat.Light主题,这是一个库项目。 You have to reference this library project to your project. 您必须将此库项目引用到您的项目中。

Now, at first, check that you have installed this library project as follows... 现在,首先,检查您是否已安装此库项目,如下所示...

Go Window --> Android SDK Manager then a window named Android SDK Manager will appear as below. 转到窗口 - > Android SDK Manager,然后会出现一个名为Android SDK Manager的窗口,如下所示。

在此输入图像描述

If the Android Support Library is not installed then install it. 如果未安装Android Support Library请安装它。 You can see more information about Android Support Library setup from the below Android Developer site. 您可以从以下Android开发者网站上查看有关Android Support Library设置的更多信息。

Support Library Setup 支持库设置

After Android Support Library setup completion, reference the library to your project from this path... 完成Android Support Library设置后,从此路径将库引用到您的项目中...

android-sdk/extras/android/support/v7/appcompat

To reference, follow these steps: 要参考,请按照下列步骤操作:

  1. File -> Import (android-sdk\\extras\\android\\support\\v7). 文件 - > 导入 (android-sdk \\ extras \\ android \\ support \\ v7)。 Choose " appcompat " 选择“ appcompat
  2. Project -> properties -> Android . 项目 - > 属性 - > Android In the section library " Add " and choose " appCompat " 在“ 添加 ”部分库中选择“ appCompat

Now, clean and build your project and run it. 现在,清理并构建项目并运行它。 I think after all of these, your problem will be solved. 我认为,经过所有这些,你的问题将得到解决。

I finally figured out the problem. 我终于弄明白了这个问题。 I had to delete this line of code from my main.xml : 我不得不从main.xml删除这行代码:

android:showAsAction="never"

Under my values-v11 and values-14 folders I changed the name of the app to... 在我的values-v11values-14文件夹下,我将应用程序的名称更改为...

style name="AppBaseTheme" parent="android:Theme.Light"

...and it is currently working. ......它目前正在运作。

Since you're using Theme.AppCompat.Light in your Theme, you have to include appCompat into your Project. 由于您在主题中使用Theme.AppCompat.Light ,因此必须将appCompat包含在项目中。

  • File->Import (android-sdk\\extras\\android\\support\\v7). 文件 - >导入(android-sdk \\ extras \\ android \\ support \\ v7)。 Choose "appcompat" 选择“appcompat”

  • Project-> properties->Android. 项目 - >属性 - > Android。 In the section library 在部分库中

  • "Add" and choose "appCompat" “添加”并选择“appCompat”

That should work. 这应该工作。

Make sure you closed the <resources> tag properly and add at the bottom of your styles.xml: 确保正确关闭<resources>标记并添加到styles.xml的底部:

 </resources>

according to your posted code snippet that is not present, but needs to be 根据您发布的不存在的代码片段,但需要

Edit: the missing resources tag was just a copy-paste bug in question, so here that was not the reason. 编辑:缺少的资源标记只是一个有问题的复制粘贴错误,所以这不是原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到资源 - Styles.xml和Theme.AppCompat.Light - No resource found - Styles.xml and Theme.AppCompat.Light 键入错误:检索项目的父项时出错:未找到与给定名称&#39;Theme.AppCompat.Light&#39;匹配的资源。 styles.xml Android AAPT - Type error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml Android AAPT 检索项目的父项时出错:找不到与给定名称“Theme.AppCompat.Light”匹配的资源。 我的R.java失踪了 - Error retrieving parent for item:No resource found that matches the given name 'Theme.AppCompat.Light'. MY R.java is missing 找不到与给定名称“ Theme.AppCompat.Light”匹配的资源 - No resource found that matches the given name 'Theme.AppCompat.Light' 找不到与给定名称“ @ style / Theme.AppCompat.Light”匹配的资源 - No resource found that matches the given name '@style/Theme.AppCompat.Light' 找不到与给定名称&#39;@ style / Theme.AppCompat.Light&#39;相匹配的资源 - No resource found that matche the given name '@style/Theme.AppCompat.Light' Android:找不到与给定名称匹配的资源:Theme.AppCompat.Light - Android: No resource found that matches the given name :Theme.AppCompat.Light Theme.appcompat.light找不到资源 - Theme.appcompat.light no resource found 寻求帮助:“错误:检索项目父项时出错:找不到与给定名称&#39;Theme.AppCompat.Light&#39;相匹配的资源” - Asking for help: “error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light' ” 如何修复Mac版的android eclips“错误检索父项:找不到与给定名称&#39;Theme.AppCompat.Light&#39;相匹配的资源? - How to fix mac version of android eclips 'Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM