以下是我的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