When I changed some design in .xml file, R.java file automatically deleted. How can I get back that file and what is the solution to resolve this problem, that in future this problem does not occure.
8 Answers
check all your errors in xml files structure (layouts, string etc...) even if sometimes they are not easy to spot.
My advice is to undo the latest things you've done until you find where the errors were and fix them.
Once they are all fixed the R
file will be created again (maybe you need to clean your project: project -> clean
)
In the future just try not to break the xml files and this won't occur again xD

- 7,478
- 3
- 37
- 32
-
This is the best answer IMO I basically fixed all the mistakes in my layout files and did Project --> Clean Thanks – Shehaaz Feb 19 '13 at 17:39
Fix your errors and the R.java file will return...e.g when i added an image in my resources folder its name was in uppercase....when i changed it to lowercase,immediately after doing it my R.java file returned...its all due to errors...just fix them and it will return

- 41
- 1
You can also disable automatic build in your Eclipse IDE(Menu -> project- > Uncheck build automatically). This way the R file will be recreated only when you manually build the project and not when you save changes in an xml file.

- 1,306
- 1
- 13
- 21
-
1This will be quite troublesome, as Eclipse will not be appending resources after R.string..., R.layout..., and else, if you don't update R.java frequently. – Aman Alam Jan 05 '11 at 11:30
-
But this will not solve the problem, only make that you don't see it until you build the project, because if when you build it manually an xml file is malformed the build will also break and you can't even know how long its broken (harder to debug) – maid450 Jan 05 '11 at 11:37
one solution is that Go to Eclipse project tab -> uncheck Build Automatically -> Clean the project.Make sure that there is no error in your project also don't try to edit the R.java file one it will created. Then manually build the project. you will get the r.java file.

- 28
- 4
The best solution for Mac/Eclipse user is to go to the SDK Manager and re-install the Android SDK Build-tools, and then restart Eclipse.
For some reason after performing a Clean action on a project the R.java file for all projects happens to be deleted from the system.
Clean the project.
Menu [Project] -> [Clean...] -> Select you project -> [OK] Project will rebuild automatically, if not, chek Menu [Project] ->[Build Automatically]

- 1
- 1
I agree with @maid450.
I also have faced similar situations.
If your problem isn't resolved after all this, ultimate option is to create a new project, and copy files to it.

- 11,231
- 7
- 46
- 81
The R file deleted automatically when I changed my activity_main.xml
in Android Studio.
What I did was copy the R java file from another project and paste it into the project in which it got deleted. Hope it helps. :).
Location for R file.
Project/app/build/generated/source/r/debug/com.android.'projectname'/R.java
-
R.java gets created automatically and its totally different from another application. Do not try this – Pankaj Kumar Jun 22 '18 at 04:54