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

rav*_*sgo 10 xml android android-appcompat r.java-file android-support-library

我是Android新手,我正在尝试运行我的第一个程序.但是,基于我在互联网上的搜索,我认为我无法导入mypackage.R因为r.java我的style.xml文件中的错误而未生成.我一直在寻找如何解决这些问题,但我找不到一个有效的修复方法.错误styles.xml

error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这一问题?

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

这是我正在使用的代码:

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;
}
}
Run Code Online (Sandbox Code Playgroud)

更新:这是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>
Run Code Online (Sandbox Code Playgroud)

更新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>
Run Code Online (Sandbox Code Playgroud)

Ham*_*atu 10

您正在尝试使用Theme.AppCompat.Light作为库项目的主题.您必须将此库项目引用到您的项目中.

现在,首先,检查您是否已安装此库项目,如下所示...

转到窗口 - > Android SDK Manager,然后会出现一个名为Android SDK Manager的窗口,如下所示.

在此输入图像描述

如果Android Support Library未安装,则安装它.您可以Android Support Library从以下Android开发者网站上查看有关设置的更多信息.

支持库设置

Android Support Library安装完成后,从该路径引用该库到您的项目...

android-sdk/extras/android/support/v7/appcompat
Run Code Online (Sandbox Code Playgroud)

要参考,请按照下列步骤操作:

  1. 文件 - > 导入(android-sdk\extras\android\support\v7).选择" appcompat "
  2. 项目 - > 属性 - > Android.在" 添加 " 部分库中选择" appCompat "

现在,清理并构建项目并运行它.我认为,经过所有这些,你的问题将得到解决.