Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R cannot be resolved to a variable in a new project [duplicate]

Possible Duplicate:
R cannot be resolved - Android error

I can't create a new android project, neither in windows or Ubuntu! I have 2.3.3 and 2.2 and 4.0 versions of android sdk and I want to create a new project using 2.3.3 version. But after creating the project it says R cannot be resolved to a variable.

I have read all the questions related to this topic and I have done all the suggested solutions but none of them worked for me. (Clean Project , check Android version in Build path menu, checking xml files, lower case xml file names and etc)

Since I'm using a blank project, it's not because of some incorrect xml files or some errors in java codes.(for god sakes its a blank project!! how could it be broken?)

I don't know what to do. any suggestions would be appreciated.

like image 232
Firouziam Avatar asked Aug 01 '12 12:08

Firouziam


3 Answers

If cleaning the project doesn't work and if there is no problem with xml files(as it is a new project). Then go to androidmanifest.xml,edit it and add some spaces between the lines, save it. Now clean the project, error will vanish.

This happens because of stale r.java file. When we edit android manifest file,R.java is created again.

like image 185
Ryhot Avatar answered Oct 20 '22 03:10

Ryhot


It happen's because of error's in XML files, review all xml files and check your Problems window. and then clean your project..

Hope it will work..

like image 1
RajaReddy PolamReddy Avatar answered Oct 20 '22 01:10

RajaReddy PolamReddy


I had exactly same problem. Here is what worked for me:

  • change SDK's folder permissions: (chmod -R 777)
  • add import android.R;
  • project->Clean
  • remove import android.R;
like image 1
Matej09 Avatar answered Oct 20 '22 03:10

Matej09