Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 652
ravensgo Avatar asked Mar 08 '14 16:03

ravensgo


3 Answers

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-sdk\extras\android\support\v7). 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.

like image 118
Hamid Shatu Avatar answered Nov 03 '22 04:11

Hamid Shatu


I finally figured out the problem. I had to delete this line of code from my main.xml:

android:showAsAction="never"

Under my values-v11 and values-14 folders I changed the name of the app to...

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

...and it is currently working.

like image 2
skm9 Avatar answered Nov 03 '22 05:11

skm9


Since you're using Theme.AppCompat.Light in your Theme, you have to include appCompat into your Project.

  • File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"

  • Project-> properties->Android. In the section library

  • "Add" and choose "appCompat"

That should work.

like image 1
Ye Lin Aung Avatar answered Nov 03 '22 03:11

Ye Lin Aung