无法解决Android Studio中的符号“菜单"错误

无法解决Android Studio中的符号“菜单

问题描述:

我正在从 Github 上提供的.

I'm learning Android Development for Beginners from Udacity and have completed making an app named Court Counter in which I wrote code for an XML (activity_main.xml) and some code for Java (MainActivity.java) file as some of the code was provided by the Udacity team on Github.

但是,当我单击"Build APK"时,我从Java文件中都得到了两个错误:

But when I click on 'Build APK' I get two errors both from the Java file:

  1. 无法解析以下代码中的符号菜单":-

  1. Cannot resolve symbol 'menu' in the following code:-

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

  1. 无法解析符号"action_settings":-

  1. Cannot resolve symbol 'action_settings':-

@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);
}

我不知道执行这些代码块时会发生什么,但是我想在手机上运行该应用程序!

I don't know what happens when these block of code are executed but I want to run the app on my phone!

我很乐意将其作为对第一个答案的注释,但是我暂时不能.因此,当我在使用Android Studio 2.3时遇到问题时.我清理项目,然后重建:

I would have love to add this as a comment to the first answer but I can't for now; So when I had the problem using android studio 2.3. I clean the project and then rebuild:

构建-> 清理项目,然后构建-> 重建项目

Build --> Clean Project and Build --> Rebuild Project