3kings
3kings

Reputation: 838

R.menu in eclipse error

enter image description here

I looked around a lot on how to fix the problem and still have not yet found a solution.

When i create a new Android Project i go through the whole process following the guide located here

This is a brand new eclipse download with the right plugins and software installed.

There errors occur here

setContentView(R.layout.activity_main);
getMenuInflater().inflate(R.menu.main, menu);

saying R cannot be resolved as a type. I know not to import android.R but it has something to deal with the R file that is suppose to be generated when created.

Any ideas on how to fix this?

Upvotes: 0

Views: 730

Answers (4)

Anand Singh
Anand Singh

Reputation: 5692

where is R.java file? When you create new activity ID automatically generated in R.java file but your project doesn't have that file. That's why you are facing that problem. As i see your gen folder is empty.

Upvotes: 0

Matej Špilár
Matej Špilár

Reputation: 2687

i had the same problem as you ... try to delete the whole menu file and create it again :)

and just for make sure that you really dont have any bad code in your xml ... try it with this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Single menu item
         Set id, icon and Title for each menu item
    -->

    <item android:id="@+id/menu_preferences"
          android:icon="@drawable/icon_preferences"
          android:title="Preferences" />
</menu>

Upvotes: 1

VipulKumar
VipulKumar

Reputation: 2395

An error in XML build can result in destroying R file. but as far as I can see, your project doesn't seem to have any error in Resources. so right click on project -> properties -> Android -> check if you have a Project build target selected. not selecting a target might be the problem.

And don't forget to CLEAN the project.

Upvotes: 2

Roysten
Roysten

Reputation: 91

Make sure there are no errors in your XML files (layout, menu, strings, ...). If these files contain errors Eclipse will not be able to build the R file, which causes this behaviour. Also sometimes something internally goes wrong in either Eclipse or the Android plugin, in which case a project clean is necessary (project -> clean projects). If that doesn't work, try restarting Eclipse.

Upvotes: 1

Related Questions