0

I have been looking for this on stack overflow for the past two hours and have tried a lot of things but nothing worked.

I have installed eclipse juno just this morning and i am getting this error R cannot be resolved to a variable in any project that I create. Also, I cannot see any files under the gen folder, even after I build the project. I have tried clean project, installed ia32 libs for my 64 bit system running ubuntu, tried changing folder positions, rebooting system but nothing worked.

The generated code is:

package tanvi.alarm;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


}

main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        />

</RelativeLayout>

manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tanvi.alarm"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Chilledrat
  • 2,593
  • 3
  • 28
  • 38
tanvi
  • 927
  • 5
  • 17
  • 32
  • http://stackoverflow.com/a/10486659/1289716 – MAC Jun 30 '12 at 09:10
  • Similar issue faced by others. This thread may help too [R cannot be resolved - Android error](http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) – Chandra Jun 30 '12 at 09:12
  • i had already read these threads..tried a lot of things..did not work..any further help will be highly appreciated – tanvi Jun 30 '12 at 09:42

7 Answers7

2

Check if you have this line

import android.R;

and if, remove it and clean and build project again.

Same thing is solved here. Check my answer.

Community
  • 1
  • 1
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
2

I had the same problem as you but in Windows, and I found a solution to it.

You have to check your SDK's folder permissions. I moved my SDK folder, which is located in my second HDD, to a new folder and it all worked perfectly.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
iPav
  • 101
  • 1
  • 7
2

After upgrading to Juno, I had this problem. It was fixed by using the Android SDK Manager to install Android SDK Build-tools.

Edmund Johnson
  • 709
  • 8
  • 15
2

I've just spent a day finding a fix for this problem.

In my case I started with Eclipse: Help->Check for Updates. These updated and I then opened the SDK manager and updated a few packages there too.

After that I had the 'R cannot be resolved error' for new projects and also the 'Could not find *.apk' in other projects

My solution was to Help->Check for Updates in Eclipse again and then open the SDK manager again and a small number of extra packages were available for an update. These updates were not available the first time I looked for updates.

I restarted Eclipse after the 2nd round of update and all was fine after that.

Hope this helps someone in the future.

TabsTheCat
  • 21
  • 2
1

If nothing above is resolved then check your /res folder where there might be an error in xml file. Due to this error R.Java file will not be updated due to which the above problem might occur. If have the error in xml file it must be probably in res-values-strings.xml. Try removing that error and also update your Androidmanifest.xml if any string values are used.

This will automatically resolve the issue.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
B N Patil
  • 11
  • 1
0

I installed Juno myself yesterday and had to faff around in the beginning but everything seems to be working now. You didn;t say which SDK you've installed, but I'm assuming you are using the latest SDK (r20) as you seem to have dotted all the other Is. However, as r20 is the only version that currently works with Juno it would be best to check if you're unsure.

Unsurprisingly the code you supplied in the question works as is, so the problem isn't there. However, if there is an error in one of the XML files in that you have supplied, you'll need fix those before the R class can be generated.

Alternatively, if you previously had a 3.x version of Eclipse installed are you still using the same workspace for for running Juno? If so I suggest starting again in a fresh workspace and see if you have the same issues. Even using -clean on the old workspace won't cut it. If you want to keep using the old workspace directory, delete the .metadata directory within it and try again, though you will need to import any existing projects afterwards.

To be honest, I'd be surprised if it was a workspace clash as I'd expect you to have more problems that just an R cannot be resolved error, but I'm just trying to cover the bases.

Chilledrat
  • 2,593
  • 3
  • 28
  • 38
  • Chilledrat Thanks a lot for your answer. But I had my problem solved, thanks to a lot of forums here on stackoverflow. Had to do a couple of things, there was this library i had to download and install, and then clicking on the Build Automatically option helped. – tanvi Jul 05 '12 at 21:09
  • @tanvi - Cool, glad you got it sorted. You should consider adding your own answer detailing the steps you went through to fix it. It may help someone else in the future ;) – Chilledrat Jul 05 '12 at 23:15
0

I had to install this library on my ubuntu 12.04, sudo apt-get install ia32-libs (my system is 64 bit). And on restart of eclipse, the files were generated.

If the problem persists, check if the Project -> Build Automatically is selected. Once selected, the project should run fine.

tanvi
  • 927
  • 5
  • 17
  • 32