4

Everything was working fine earlier. I then happened to add a new xml file to my layouts. now, one of my classes is giving an error when setContentView points to (R.layout.menu). Eclipse is telling me that R.layout.menu cannot be resolved. I can't figure out why; I have a layout called menu defined in my layout folder.

Any suggestions?

EboMike
  • 76,846
  • 14
  • 164
  • 167
LuxuryMode
  • 33,401
  • 34
  • 117
  • 188
  • Did you import the wrong R? Did your app's R get regenerated properly? – EboMike Nov 25 '10 at 02:32
  • To get more accurate help, you should post exactly what "error" you are getting rather than just saying you're getting an error. Eclipse will tell you what's wrong, but if you can't solve it on your own, tell us what Eclipse is telling you. – Snailer Nov 25 '10 at 02:48
  • Uh, I said "Eclipse is telling me that R.layout.menu cannot be resolved" – LuxuryMode Nov 25 '10 at 12:54

6 Answers6

4

Did you do a Project > Clean? Sometimes you just have to let Eclipse generate the R file again.

Zarah
  • 5,179
  • 2
  • 29
  • 29
  • R.java is not created when there is issues with the resource folder. If thats not the case then just clean the project as Zarah suggested. – Manish Khot Nov 25 '10 at 02:39
2

lowercase XML filename(not sure if this is a must)

check your androidmanifest if the activity(class file) is added over there

if my class file name is abc.class

my android manifest should have this line

<activity android:name=".abc"></activity>
1

See R cannot be resolved - Android error

Community
  • 1
  • 1
Michael Levy
  • 13,097
  • 15
  • 66
  • 100
0

Also, check if you've imported android.R.

Delete that line, and your project should pull from its own R file.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Ryan K
  • 11
  • 1
0

This may not be your problem, but I had a nasty problem, related to Eclipse's tendency to snowball errors. I have an app with lots of graphics. I mistakenly saved one of the graphics in ny graphics editor as PSP type (Paint Shop Pro) but with a PNG extension. Because of this, I got the following errors:

[2010-12-21 13:49:04 - TSRemote] W/ResourceType( 4112): Bad XML block: no root element node found
[2010-12-21 13:49:04 - TSRemote] libpng error: Not a PNG file
[2010-12-21 13:49:04 - TSRemote] ERROR: Failure processing PNG image ...\android\TSRemote\res\drawable\reset_normal.png
[2010-12-21 13:49:04 - TSRemote] ...\android\TSRemote\res\layout\devices.xml:38: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/deviceback').
(about 50 more of these -- one for every graphic).

Plus, in the IDE, every reference to R. was unresolved.

The key was the incorrect PNG file. Once I fixed that, all the other errors went away.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
user199395
  • 99
  • 2
0

This happens sometimes.

Assuming that there are no errors in the xml files:

1 Make some harmless change in one in the xml files, like adding a string

2 Project > Clean

Repeat until it works.

Giulio Prisco
  • 941
  • 9
  • 16