Android – R cannot be resolved to a variable – Eclipse trick to find the error

androideclipse

I have an issue that many people had, looking at the numerous questions, which is described in the subject : sometimes, R.java disappears and after some (far too long) minutes of changing back what I did, R.java comes back. When R.java isn't generated, lines calling for R show the error : 'R cannot be resolved to a variable'.

I know that R isn't the real problem, and that there is one or more error somewhere in my code.

My question is : how to localize these errors, provided Eclipse doesn't show them?

If you have the same problem as me, first see "R cannot be resolved to a variable"? which can help you getting rid of that mercyless error

Best Answer

If you're trying to pinpoint the source of this error, try this:

  1. Go to Project -> Clean. This will ensure that your error wasn't because of a bad build. If R can still not be found, move onto step 2.
  2. You should have a Problems tab in Eclipse which will list out all the errors and warnings in open projects, as shown in the screenshot below. If you can't see the Problems tab, go to Window -> Show View -> Problems
  3. Expand the Errors section to see what problems are present. You will be told the problem, the project, the file and the line number in most cases.

enter image description here

Related Topic