热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法解决AndroidStudio中的符号“菜单”错误-Cannotresolvesymbol'menu'errorsinAndroidStudio

ImlearningAndroidDevelopmentforBeginnersfromUdacityandhavecompletedmakinganappnamedC

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.

我正在学习Udacity的初学者Android开发,并完成了一个名为Court Counter的应用程序,我在其中编写了一个XML代码(activity_main.xml)和一些Java(MainActivity.java)文件代码,因为提供了一些代码由Github的Udacity团队负责。

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

但是当我点击'Build APK'时,我从Java文件中得到两个错误:

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

    无法在以下代码中解析符号'menu': -

    @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. Cannot resolve symbol 'action_settings':-
    2. 无法解析符号'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! Please help.

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

Thanks, Kvaibhav01.

3 个解决方案

#1


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:

我很乐意将此作为对第一个答案的评论,但我现在不能;所以当我遇到使用android studio 2.3的问题时。我清理项目,然后重建:

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

构建 - >清理项目和构建 - >重建项目

#2


4  

Check menu_main.xml is in your res directory. After its not working means, Once, Clear Your project.

检查menu_main.xml是否在res目录中。在它不工作之后,一次,清除您的项目。

enter image description here

#3


1  

Try this 1) "alt+enter" (R.menu.menu_main, menu)
2) click on make a menu main.xml file (a new file) 3) Disable your antivirus 4) Run the app

试试这个1)“alt + enter”(R.menu.menu_main,菜单)2)点击制作一个菜单main.xml文件(一个新文件)3)禁用你的防病毒软件4)运行app


推荐阅读
author-avatar
暧gx祢生
这个家伙很懒,什么也没留下!
RankList | 热门文章