以下是我的android程序的代码片段,我面临着两个错误。一个是在R.menu.menu_main
,它显示主要错误为Cannot Resolve Symbol "menu"
,另一个在R.id.action_settings
,它也显示action_settings Cannot Resolve the Symbol
。无法解析符号'action_settings'
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
这里是activity_main XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
在人们开始建议如何解决“无法解决问题”之前,您可以发布您的menu_main.xml吗?并告诉我们它存储在哪个文件夹? –
检查您的R进口 – njzk2