I am a beginner in Android Development. In my first android project I'm getting an error: R cannot be resolved. I googled and tried so many things but I still can't understand how to get rid of this issue. Please anyone can tell me how to add R.Java file to gen directory??
-
1check your resource files for errors. – Raghunandan Jun 30 '13 at 07:41
-
Do you have R.java file? In some classes, R import is being imported automatically (in Eclipse) and it is wrong sometimes. By deleting the import from a class sometimes solves the problem – Boris Mocialov Jun 30 '13 at 07:50
-
no R.Java file is not there in gen dir I want to know how to add it manually.Because it is not generate automatically. – astrodileepa Jun 30 '13 at 08:39
3 Answers
These kind of problems can generally be solved by doing a clean build. Assuming you're using Eclipse, go to Projects > Clean > Then select your project.
The R.java file should get automatically regenerated. It'll be placed in the 'gen' directory of your project.
Failing that, there's almost certainly something wrong with your resources, as Raghunandan suggests. Look in the "Problems" view of Eclipse for errors in one of your XML files.

- 3,703
- 2
- 21
- 43
-
Yes im using eclipse i did what you said but it isn't work for me.In gen directory there are no any files it is empty.So what i can do ? – astrodileepa Jun 30 '13 at 08:38
check your resources for any errors If there are no errors,check you imports and remove "import android.R" and then go to Projects > Clean > Then select your project.

- 12,395
- 5
- 41
- 64
Just delete Bin and Gen folder from the project and clean it up and build the project again. If it is not fixed then, check your all the sub-folders of your resource folder,you possibly had some error in some of your XML file.

- 1,200
- 1
- 16
- 34