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:
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.andrewq.planets.MainActivity" >
android:icon="@drawable/action_about"
android:title="@string/action_about"
android:orderInCategory="1"
android:showAsAction="always"/>
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
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:
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
解决方案
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.