0

I cleaned my project and now I get a "R cannot be resolved to a variable." It was fine before I cleaned it.

I have tried cleaning it again, building the project again, creating a new project and copying all my files over, and I've gone to the Android SDK Manager and installed all the "Android SDK Build-tools" to Install all the options like the other stackoverflow posts have mentioned: enter image description here

Can anyone suggest anything?

enter image description here

The above picture shows my generated files and lack of an R.java file.

When I check the Problems

The above picture shows my problems log.

Opal
  • 471
  • 1
  • 7
  • 20
  • try window ->show view -> other -> General -> problem , and search in this tab on your project you will the error why it can't generate the R file – mohammed momn Feb 14 '14 at 00:13
  • 2
    An error in an XML file can cause this issue. Be sure to double check all XML file names (all lower case letters and must start with a letter) and the contents for a syntax error. – Tigger Feb 14 '14 at 00:21
  • @mohammedmomn I added a screenshot of my General -> Problem – Opal Feb 14 '14 at 00:31
  • Make sure that all your images are lower case – Ushal Naidoo Feb 14 '14 at 02:59

2 Answers2

1

Make sure R is in the same package as the file where you want to call it from. (or import the package in the source file)

To change the package of the R file open your App Manifest file and change packge="" to the same package as where your source files are in.

eclipse-image

Ansgar
  • 371
  • 3
  • 15
  • It's the same (see above, I added a screenshot) – Opal Feb 14 '14 at 00:27
  • 1
    Uh sorry. But your R.java file is clearly not existing. Have you tried just deleting the package in gen/ ? If your IDE doesn't rebuild that package (including the R file) I suspect you have an error in a xml file. – Ansgar Feb 14 '14 at 00:31
  • yes, when I try to clean, it does not build the R.java file. – Opal Feb 14 '14 at 00:35
  • 1
    Do you have an error in a xml file ? For me eclipse sometimes doesn't highlight xml errors like it does with errors in code. Try to restart eclipse and/or look in the console. – Ansgar Feb 14 '14 at 00:41
0

maybe you import take other thing

See package main import in your code should be like this example:

import com.mypackageprincipal.R;

other import of R delete only should exist it

and after clean and build your project

Quickcoding
  • 735
  • 8
  • 14
  • If I do the import statement, then along with other new errors, it states my activity_main "cannot be resolved or is not a field" – Opal Feb 14 '14 at 00:33
  • also u can create new project wiht activity of same name and after take files .java and your AndroidManifest.xml also your folder name res if you have files of your old project and overwrite on new and compile – Quickcoding Feb 14 '14 at 00:52