Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Shane McC
Shane McC
3,005 Points

R cannot be resolved to Variable error, missing R.java?

Hi Everyone

I just recently upgraded my eclipse software. I'm getting this error in every single file for my app "R cannot be resolved to a variable". I'm also missing the R.java file from my gen folder. I know I need my R.java file for my app to work. My question is, how would I get my app running properly again? How should I fix this problem?

I would also like to add two of my XML files have errors.

Error 1 In folder called values-v11 styles.xml I'm getting an error called "Error: retrieving parent for item. No resource found that matches the given name android:Theme.Holo.Light.DarkActionBar"

Error 2 In folder called values-v14 styles.xml I'm getting an error called "Error: retrieving parent for item. No resource found that matches the given name android:Theme.Holo.Light.DarkActionBar"

Thanks

Shane McC
Shane McC
3,005 Points

I've since renamed my styles.xml files to <style name="AppBaseTheme" parent="android:Theme.Light"> and that has seemed to correct the program regarding those two files but I'm still getting the R cannot be resolved to Variable error on every file in my app. Any help would be appreciated. Thanks

3 Answers

Hmm... Did you change your android manifest? Whats your minSdkVersion? It might not be compatible with the Hole Theme.. Did you check that?

Shane McC
Shane McC
3,005 Points
    Hi Everyone

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

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's currently working

I had that error before.. Even though I don't have eclipse and android sdk installed right now to tell each step you need to do, basically you just need to rebuild your project. Also check out this link: http://stackoverflow.com/questions/7824730/r-cannot-be-resolved-to-a-variable

Shane McC
Shane McC
3,005 Points

Bernardo, I've since added to my question. I think the problem might lay in a few of my XML files. I've rebuilt my project before but that didn't work.

Shane McC
Shane McC
3,005 Points

Bernardo

Below is my syntax for the android manifest. My minSdkVersion is 8.

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>

I've since renamed my styles.xml files to <style name="AppBaseTheme" parent="android:Theme.Light"> and that has seemed to correct the program regarding those two files but I'm still getting the R cannot be resolved to Variable error on every file in my app. Any help would be appreciated. Thanks

When I rebuild my project I'm getting this error in my console [2014-03-16 10:48:45 - ThisIsATestProject] W/ResourceType( 5756): ResXMLTree_node header size 0 is too small. [2014-03-16 10:48:45 - ThisIsATestProject] C:\workspace\ThisIsATestProject\res\menu\main.xml:3: error: No resource identifier found for attribute 'showAsAction' in package 'android'

Below is my entire manifest

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>

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

         <activity
            android:name="com.example.thisisatestproject.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.thisisatestproject.STARTINGPOINT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

         <activity
            android:name=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.thisisatestproject.MENU" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

         <activity
            android:name=".AboutUs"
            android:label="@string/app_name" 
            android:theme="@android:style/Theme.Dialog"
            >
            <intent-filter>
                <action android:name="com.example.thisisatestproject.ABOUT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Prefs"
            android:label="@string/app_name" 
            android:theme="@android:style/Theme.Dialog"
            >
            <intent-filter>
                <action android:name="com.example.thisisatestproject.PREFS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

         <activity
            android:name=".TextPlay"
            android:label="@string/app_name" >
        </activity>

         <activity
            android:name=".Email"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name=".Camera"
            android:label="Camera App" 
            android:screenOrientation="portrait"
            >
        </activity>

        <activity
            android:name=".Data"
            android:label="Camera App" 
            android:screenOrientation="portrait"
            >
        </activity>

         <activity
            android:name=".GFX"
            android:label="Camera App" 
            android:screenOrientation="portrait"
            >
        </activity>

        <activity
            android:name=".GFXSurface"
            android:label="Camera App" 
            android:screenOrientation="portrait"
            >
        </activity>

        <activity
            android:name=".SoundStuff"
            android:label="Camera App" 
            android:screenOrientation="portrait"
            >
        </activity>

         <activity
            android:name=".PlayMusic"
            android:label="Play Music" 
            android:screenOrientation="portrait"
            >
        </activity>

        <activity
            android:name=".ChooseMusic"
            android:label="Play Music" 
            android:screenOrientation="portrait"
            >
        </activity>

        <activity
            android:name=".Slider"
            android:label="Play Music" 
            android:screenOrientation="portrait"
            >
        </activity>

        <activity
            android:name=".OpenedClass"
            android:label="Camera App" 
            android:screenOrientation="portrait"
            >
        </activity>

    </application>

</manifest>