我要疯了!我有这个来源,但为什么会出错?
这是 MainActivity 的 Menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<group android:id="@+id/group1">
<item android:id="@+id/item1" android:title="X"></item>
<item android:id="@+id/item2" android:title="Y"></item>
<item android:id="@+id/item3" android:title="Z"></item>
<item android:id="@+id/item4" android:title="Share"></item>
</group>
</menu>
这是Java文件
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
CODE
}
return true;
case R.id.item2:
CODE
return true;
case R.id.item3:
CODE
return true;
case R.id.item4:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "hXXX");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this site!");
startActivity(Intent.createChooser(intent, "SHARE"));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
为什么在这一行给我一个错误:case R.id.item4: The error is Multiple markers at this line - item4 cannot be resolve or is not a field - item4 cannot be resolve or is not a field