Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - R cannot be resolved to a variable [duplicate]

Possible Duplicate:
R cannot be resolved - Android error

I am having a issue which I have had before and I don't understand the cause. My project and code is fine as it was running yesterday. I have open Eclipse today and the whole project looks like it contains errors.

I believe it is some sort of build path issue. I don't understand why it randomly occurs? But in the code where there is R.Layout.LayoutName there is an issue... can anyone help?

I have tried cleaning and building it, I have tried importing android.R but I didn't have this before, it then gives and error and says the layout file doesn't exist.

like image 435
Beginner Avatar asked Feb 08 '11 11:02

Beginner


People also ask

What does it mean when something Cannot be resolved to a variable?

If you try, the cannot be resolved to a variable error will come out. It means it cannot detect the initialization of variables within its scope. Similarly, if you make a private variable, you cannot call it inside a constructor. Its scope is out of bounds.


2 Answers

I think I found another solution to this question.

Go to Project > Properties > Java Build Path > tab [Order and Export] > Tick Android Version Checkbox enter image description here Then if your workspace does not build automatically…

Properties again > Build Project enter image description here

like image 136
Emkey Avatar answered Oct 13 '22 06:10

Emkey


Are you targeting the android.R or the one in your own project?

Are you sure your own R.java file is generated? Mistakes in your xml views could cause the R.java not to be generated. Go through your view files and make sure all the xml is right!

like image 27
codinguser Avatar answered Oct 13 '22 04:10

codinguser