I don't why the hell is R file getting lost. Everytime I build my project everything is fine. Sometimes I get errors while running my android project and sometimes my Eclipse gets crashed. At this situation when I restart eclipse my project will show compilation errors. Even after solving those things, When I build my project the R file is getting lost exactly at that time. And even if I import the R file the errors will move to the next variable. Is there any way to recover the R file or to protect it from getting lost???????
-
1Its definitely problem in your xml layout. That's why it error occur. Please double check your layout file. – Darshak Feb 13 '16 at 12:38
-
from where you are importing R file? – Mangesh Sambare Feb 13 '16 at 12:38
-
1@Sam I think R file generated by android it self. where you from? – Shabbir Dhangot Feb 13 '16 at 12:39
-
1@Sam R file automatically generated by project it self. No need to import it – Darshak Feb 13 '16 at 12:39
-
`R.java` is regenerated from resources on each build. If you have errors in a resource or in your manifest, that will prevent `R.java` from being rebuilt. You cannot "recover" or "protect" `R.java`, but you can fix whatever problems there are in your resources or manifest. You may also wish to switch to an IDE that has a supported path for Android work. Google has dropped Eclipse support, and [Andmore](https://projects.eclipse.org/projects/tools.andmore) is still a work in progress. Consider Android Studio or IntelliJ IDEA. As a bonus, they provide better error information for this problem. – CommonsWare Feb 13 '16 at 12:41
-
Yes, R file will be generated automatically by android itself. And I found another problem. My xml layout file's Graphical Layout view is disabled and I don't know how to enable it :( – Joshua Feb 13 '16 at 12:47
-
Just try to use different API level for UI rendering. – Darshak Feb 13 '16 at 12:50
-
try to **clean** your project and **re-bulid** your project...just check your .XML files code or drawable folder file name properly written. – Viveka Patel Feb 13 '16 at 12:52
-
Actually I am new to android and the bad thing is my system configuration is low to work with android stduio. Thank you all for your support :) and I will be happy if there is any other solution. – Joshua Feb 13 '16 at 12:55
-
@Darshak, Yes I even tried that but that did'nt help. UI rendereing is also disabled :( – Joshua Feb 13 '16 at 12:59
-
@VivekaPatel I tried do that everytime I update code in my project, sometimes at this point the R file is getting lost. – Joshua Feb 13 '16 at 13:01
-
check your update in SDK manager... [LINK](http://stackoverflow.com/questions/16608524/eclipse-giving-error-missing-r-java-file-after-recent-update) – Viveka Patel Feb 13 '16 at 13:05
-
@Joshua what have make last changes into the resources. Have you added any drawable or changes in style or any layout xml changes? because this will cause you the R missing error. – Shabbir Dhangot Feb 13 '16 at 13:08
-
@VivekaPatel Everything is up to date except one file which is Android SDK Tools under Tools (Preview Chennel). Whenever I try to update it its showing some error and the update gets terminated. – Joshua Feb 13 '16 at 13:20
-
@CreativeAndroid I have not made any changes style or layout and I have not added any drawable but still the R file is getting lost. – Joshua Feb 13 '16 at 13:24
-
Even when I create a new layout file the Graphical Layout is disabled and I am not able to perform any UI rendering only the Pallete options are available – Joshua Feb 13 '16 at 13:28
2 Answers
Generally this happens when you have an error in one of your xml files.Another possible reason is that you initially wanted to have your R class not in the default place where it is created but in your own package. So it is possible that R is created in its default location and your program is looking for it somewhere else.

- 765
- 6
- 9
-
Actually in code level there is no error in the xml files, the only problem with the xml file is that the Graphical Layout is disabled i.e I cannot perform any UI rendering and I am not getting any layout visually although the layout is declared and defined in code. – Joshua Feb 13 '16 at 13:15
-
Today I noticed I thing. The xml file in the layout does'nt show error externally. When I was just surfing through it I found a Tab named ERROR LOG. Only in that Tab all the internal errors are visible and Unfortunately, I have no idea how to solve it :( – Joshua Feb 15 '16 at 03:47
if your project R file not generated automatically then this are the possibility i mention below.
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
Go to Project and hit Clean. This should, among others, regenerate your R.java file.
Also get rid of any import android.R.* statements and then do the clean up I mentioned.
Check your latest updates in SDK manager if possible some remain to update.
Also check target build was set to Android 2.1 (SDK v7) where his layout XML used Android 2.2 (SDK v8) elements (layout parameter match_parent), due to this there was no way for Eclipse to correctly generate the R.java file which caused all the problems.

- 666
- 7
- 17
-
You did not get my question properly. The R file is Generating fine in the beginning. When I do changes in my code and when I perform many clean and build operations, suddenly the R file will get lost. I dont know how and why it is happening. – Joshua Feb 13 '16 at 13:33
-
Today I noticed I thing. The xml file in the layout does'nt show error externally. When I was just surfing through it I found a Tab named ERROR LOG. Only in that Tab all the internal errors are visible and Unfortunately, I have no idea how to solve it :( – Joshua Feb 15 '16 at 03:47