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?
Did you do a Project > Clean? Sometimes you just have to let Eclipse generate the R file again.
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>
Also, check if you've imported android.R
.
Delete that line, and your project should pull from its own R file.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.