15

Possible Duplicate:
Developing for Android in Eclipse: R.java not generating

enter image description hereI cleaned my project and changed my project files name.I am getting "R cannot be resolved to a variable".When i clean the project nothing happens and my /gen/ folder is still empty.I was trying to show u guys an image of the situation but unfortunately i cant due to my low reputation. I hope this can be helpful.

Community
  • 1
  • 1
Mj1992
  • 3,404
  • 13
  • 63
  • 102
  • how about now? you should be able to post an image now – dldnh Mar 21 '12 at 18:55
  • its saying : We're sorry, but as a spam prevention mechanism, new users aren't allowed to post images. Earn more than 10 reputation to post images. – Mj1992 Mar 21 '12 at 18:58
  • There are probably errors in your resources, check them carefully and resolve all the problems there. After that the R.java should be generated. – Egor Mar 21 '12 at 18:58
  • but @Egor there is no sign of a red cross in my 'res' folder. – Mj1992 Mar 21 '12 at 19:00
  • I upvoted your question so that you have more than 10 reputation - you should be able to post the image now. You also should have a look into the console - most likely you have an error in your resources and that should show up there. – ligi Mar 21 '12 at 19:00
  • I had this bug before. I did exactly what you did. Hmm... Don't remember how it got fixed. Do me a favour and post a pick on the gen>your package>R.java. See if the generated (File).xml is in there. – sdfwer Mar 21 '12 at 19:07

7 Answers7

24

Typically if the R .* can not be generate means that you have some issue into the res/ folder. Check for errors in res/ folder.

Invalid file name: must contain only [a-z0-9_.]

all the res/* filename should be named with lowercase character, underscore and number between 0 and 9

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • but the res/folder does not show any cross is there a possibility of an error without a red cross in the folder also ?? – Mj1992 Mar 21 '12 at 19:04
  • 1
    look the eclipse console. you should find "Invalid file name: must contain only [a-z0-9_.] " – Blackbelt Mar 21 '12 at 19:06
  • i changed my xml files name in the res/folder before the error occured.As you can see i've changed the main.xml to Mz_Sms_SearchOptions.xml is that causing the problem? but i tried renaming it to main.xml again it doesnt work – Mj1992 Mar 21 '12 at 19:06
  • 1
    you can name it mz_sms_searchoptions.xml but not Mz_Sms_SearchOptions.xml . – Blackbelt Mar 21 '12 at 19:07
  • i did that but that did'nt help – Mj1992 Mar 21 '12 at 19:12
  • I see. check the eclipse console for this kind of the error. Of course the same rule apply to the other res/ folder – Blackbelt Mar 21 '12 at 19:14
  • oh yeah its showing the uppercase lowercase errors in the console but they are already solved. Now the only problem is that my R.java is also created but I am not able to access my xml like this R.layout.mz_smssearchoptions – Mj1992 Mar 21 '12 at 19:19
  • that s another issue. Try to resolve. if you can not open a new post – Blackbelt Mar 21 '12 at 19:20
  • @blackbelt Sir : Take a look please http://stackoverflow.com/questions/22602559/how-do-implement-this-in-android –  Mar 25 '14 at 05:23
2

The problem is that your layout files contain uppercase letters, which is prohibited. You can use only lowercase letters and the "_" symbol (not sure about numbers). Change the filenames and clean your project. Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130
1

Did you rename your Application Package? To do that, right-click your prject in the "Package Explorer" and expand "Android Tools" then click "Rename Application Package".

davehale23
  • 4,374
  • 2
  • 27
  • 40
  • srt but @davehale23 how would that help? – Mj1992 Mar 21 '12 at 19:03
  • @Mj1992 can you please tell how the issue is resolved. – Kishore Oct 29 '12 at 11:12
  • it is caused due to the error in one of you `res/folder` files.Make sure all your xml files are in lower case letters.Or see the answer above I've mentioned as correct.Then clean the project in the end after resolving these errors. – Mj1992 Oct 29 '12 at 15:15
1

Did you change your package names as well? If so you need to remember to update that in your AndroidManifest.xml.

CaseyB
  • 24,780
  • 14
  • 77
  • 112
  • i changed my package name in AndroidManifest.xml and showed up the R.java file thnx but still when i do R.layout instead of the showing me the xml files like R.layout.mz .... it shows android.R.... – Mj1992 Mar 21 '12 at 19:13
  • Have you imported android.R into the java file? – CaseyB Mar 21 '12 at 19:14
  • actually it is not picking up my xml files in my layout folder. I removed the wrong package import at the top it goes to R.layout but after that does not show me my xml file like R.layout.myfile.xml – Mj1992 Mar 21 '12 at 19:15
  • After making sure that everything is imported correctly try doing a clean. – CaseyB Mar 21 '12 at 19:16
  • everything is fine but i dont know why it is not giving men the option for R.layout.mz_searchoptions.xml instead of that it is showing me android.R.layout. – Mj1992 Mar 21 '12 at 19:21
1

Let's try a wild guess. Right click your project > properties> Builders> Make sure everything is checked.

Reason for this is because the builder found under properties is also responsible for generating the res items in the gen folder.

sdfwer
  • 1,042
  • 3
  • 10
  • 23
1

Were you trying to use the Compatability libraries? Or any extra libraries at all (beyond the standard Android(SDK version).jar?

I ask because I recently had this problem, but it was all related to the libraries I had added. I'd be glad to go into more depth if so.

Davek804
  • 2,804
  • 4
  • 26
  • 55
  • no i did not include any libraries – Mj1992 Mar 21 '12 at 19:15
  • i did first it was not giving me any problem but sonner i move to v7-appcompat it start giving me error of duplicate sha i deleted the v4 jar file and that error gone but after that R file is not generating no spelling issue on any of resource directory than what's the problem – Khurram Iqbal Aug 05 '15 at 19:07
1

Take a look at what package your gen -> R.java is in. your Activities need to be in the same package.

Package Exporer should look somthing like this.

src -> com.foo.bar -> file1.java

gen -> com.foo.bar -> R.java

Laith Alnagem
  • 654
  • 6
  • 13