R.layout.menu could not be allowed

Everything worked well before. Then I had 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 tells me that R.layout.menu cannot be resolved. I can’t understand why; I have a layout called a menu defined in my layout folder.

Any suggestions?

+4
source share
6 answers

Have you done the project> Clean? Sometimes you just need to let Eclipse generate the R file again.

+4
source

lower XML file name (not sure if this is required)

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

if my class file name is abc.class

my android manifest should have this line

<activity android:name=".abc"></activity> 
+2
source

This may not be your problem, but I had an unpleasant problem with the Eclipse tendency to snowball errors. I have an application with lots of graphics. I mistakenly saved one of the graphic elements in the ny graphics editor as a PSP type (Paint Shop Pro), but with the 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). 

In addition, in the IDE, every reference to R. was unresolved.

The key was the wrong PNG file. As soon as I fixed this, all other errors disappeared.

0
source

It happens sometimes.

Assuming there are no errors in the xml files:

1 Make some harmless changes in one of the xml files, for example, add the line

2 Project> Clear

Repeat until it works.

0
source

Also, check that you have imported android.R .

Delete this line and your project should extract from its own R file.

0
source

All Articles