10

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>
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
ravensgo
  • 502
  • 3
  • 8
  • 26

4 Answers4

9

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.

Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
  • that just created another error- `error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Light'.` – ravensgo Mar 08 '14 at 16:30
  • Where do I find the LogCat? (In Eclipse) – ravensgo Mar 08 '14 at 16:38
  • now there is no error for theme.light! I am not sure what I did, I was just trying to include appcombat in project, then i checked back and there is no error in styles.xml – ravensgo Mar 08 '14 at 17:09
  • however, there are still errors in the `styles.xml`s that are in values-v11 and values-v14 – ravensgo Mar 08 '14 at 17:09
  • @ravensgo...see my updated answer...and forget about the previous answer. – Hamid Shatu Mar 08 '14 at 19:00
  • I did what you said and now there is no error in the styles.xml files in values-11 and values-14, but there still is in values. Do you know what mistake I may have made or is there a way to check if I did it correctly? – ravensgo Mar 08 '14 at 23:25
2

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.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
skm9
  • 33
  • 8
1

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.

Ye Lin Aung
  • 11,234
  • 8
  • 45
  • 51
  • It says select an import source, I tried typing filter text as android-sdk\extras\android\support\v7 and appCombat but nothing came up. What am I supposed to select? – ravensgo Mar 08 '14 at 16:28
  • Oh you have to go your sdk folder and `appcompat` folder located under `extras/android/support/v7/appcompat` .. – Ye Lin Aung Mar 08 '14 at 18:41
0

Make sure you closed the <resources> tag properly and add at the bottom of your 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.

donfuxx
  • 11,277
  • 6
  • 44
  • 76
  • my bad, I just didn't put four spaces in front of the end tag and it didnt show up in code... it was there in the actual xml doc – ravensgo Mar 08 '14 at 16:31
  • ok then I suggest you just switch to another theme like the mentioned "android:Theme.Light" that should be pretty fine for an HelloWorld app – donfuxx Mar 08 '14 at 16:34
  • uy, then I think it makes sense to take a look at your AndroidManifest.xml, maybe post it as well. – donfuxx Mar 08 '14 at 16:39
  • also the manifest seems ok... maybe try this answer: http://stackoverflow.com/a/19886189/2399024 – donfuxx Mar 08 '14 at 16:59