Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

android - 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. 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. 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

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]

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:

<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

<?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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are trying to use Theme.AppCompat.Light theme which is a library project. 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.

enter image description here

If the Android Support Library is not installed then install it. You can see more information about Android Support Library setup from the below Android Developer site.

Support Library Setup

After Android Support Library setup completion, reference the library to your project from this path...

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

To reference, follow these steps:

  1. File->Import (android-sdkextrasandroidsupportv7). Choose "appcompat"
  2. Project-> properties->Android. In the section library "Add" and choose "appCompat"

Now, clean and build your project and run it. I think after all of these, your problem will be solved.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...