I’ve just come across a rather irritating habit of the ADT toolset for Eclipse and thought I’d share it.
If you get a red line under “R” in a reference to a layout, string or id, (e.g. the “R” in R.layout.main) then your problem could be one of the following:
- You have ‘android.R’ as an import in your java class. This should not be there, remove it
- You need to ‘clean’ your project by going to Project > Clean on the Eclipse menu bar
- You do not have Eclipse set to ‘Build Automatically’. Do this by going to Project in the menu bar and ticking ‘Build Automatically’
My problem, however, was none of these. Eclipse just refused to generate R.java.
It turns out that if you have any errors in your xml files (strings.xml, layouts, etc.), then your R.java file will not be generated and you will not be told this is the reason.
Make sure any errors in your xml files are fixed and your R.java file should be generated automatically when you save.
4 Responses to “When Eclipse won’t generate/locate R.java”
on February 25th, 2011 at 4:47 pm #
[…] When Eclipse won’t generate/locate R.java (Updated link) […]
first R.java is visible but id and layout are not automatically updated in R.java file. Then i clean up my project and then r.java is not found in my project it totally removed. Please reply it me soon..
Hello, the whole thing is going well here and ofcourse every one is sharing information, that’s really fine,
keep up writing.
R.java file is not visible under gen folder. Tried all possible steps which are given above but still it’s not showing.. pls help me..