R.java disappears after project clean

After I added some .png files into my Project Workspace drawable folder I refreshed my drawable folders in Eclipse and the newly added files showed up. But when I tried to access those resources using R.drawable.xyzimage, xyzimage although in the folder could not be resolved.

So I did a Project Clean and guess what after this clean R.java is totally gone and all my classes accessing resources using R.java is showing all sorts of error and Eclipse won't let me run the code anymore.

I have backup of my source code but I want to explore if R.java can be regenerated and how?

Thanks for all the help.


Try Project->Clean in Eclipse. In my limited experience if R.java is not being automatically created then there is an error somewhere in your xml. Triple check everything.


You have to build the project to be able to use the newly added resources.

Cleaning a project removes all auto-generated files. Building the project it should automatically create them. When you Clean a project, there's an option to start a build immediately after clean up.

Here's a few things you can try (did the same procedure after manually deleting the "gen" directory.

  • After you have deleted the gen directory, go to Project > Clean ...
  • You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
  • Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.

Let me know if this works for you.


Here is what the problem was. I added those new png images to the project and android has rules as to what characters are allowed in the names of these images. Once I changed the uppercase letters in the image name, it was back on track again and Build Automatically generated the R.java file and all errors were gone. Eclipse console is the place where I found all the errors related to my resources.

Thanks Guys....I tried your solutions but my error was something specific which was due to my image naming convention so this is the way I fixed it.