Reputation: 2293
I have a slight issue. When I add items to the menu.xml file, the R.java file in the gen folder does not generate. I've used the same code before and no problems have arisen. I am using Eclipse with the ADT plugin on Windows 7.
Here is the menu.xml file code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.andrewq.planets.MainActivity" >
<item android:id="@+id/action_about"
android:icon="@drawable/action_about"
android:title="@string/action_about"
android:orderInCategory="1"
android:showAsAction="always"/>
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
And here is the code used in MainActivity.java:
//Method used to inflate the menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//Method used to add items to the menu
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.action_about:
aboutMenuItem();
break;
case R.id.action_settings:
Intent intent = new Intent(getApplicationContext(), Settings.class);
startActivity(intent);
break;
}
return super.onOptionsItemSelected(item);
}
FYI -- Here is some Manifest information:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
EDIT: The problem seems to arise when the items are added to the menu.xml files. If I delete the items, it just says it can't find action_about
or action_settings
whereas when the items are there the R.java file disappears.
EDIT #2: Here are some screenshots of code setup:
Here is a picture of the XML code with the items commented out.
And the Java code while items are commented out says that it can't find action_settings or action_about:
And finally, the errors output while items are commented out:
Now if I take the comment brackets out like so:
The following errors arise which can't seem to be solved:
I hope this can help someone solve my problem. I've never had this problem before.
Thanks,
Andrew
Upvotes: 1
Views: 508
Reputation: 894
I can see this:
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
Change app:showAsAction to android:showAsAction and check. Hope it will fix the problem.
Edited (on 30 Dec 2013): Can you just copy paste following code in your menu.xml and see if it works
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_about"
android:icon="@drawable/action_about"
android:orderInCategory="1"
android:showAsAction="always"
android:title="@string/action_about"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
There is only change of showAction for both the item. I have this xml and its working fine at my end.
Upvotes: 3
Reputation:
In ADT go into "Navigate" (menu) --> Preferences --> Android --> Build --> Build Config: set this to build the output as "Normal". After doing this, clean and rebuild the project.
Upvotes: 0
Reputation: 1020
Replace your last return statement return super.onOptionsItemSelected(item);
with either
return true
; or return false
based on your need as the method requires a boolean
return statement .
Upvotes: 0
Reputation: 3874
It's not deleting itself, it's not getting generated for the changes that you've made. So I suggest you clean the project, rebuild it, and if it still shows issues, go to the console and check the issues. If nothing shows there, open problems view and check it. Surely it will suggest some errors. Please take a look at error log too.
EDIT: remove showAsAction="never" from menu if your using API 11 or below or set min SDK version to 11 in manifest file.
Upvotes: 3