Java 无法解决 Android Studio 中的符号“菜单”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38226254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot resolve symbol 'menu' errors in Android Studio
提问by Kvaibhav01
I'm learning Android Development for Beginnersfrom Udacityand have completed making an app named Court Counterin 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 Development for Beginners并完成了一个名为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:
但是当我点击“构建 APK”时,我从 Java 文件中得到两个错误:
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; }
无法解析以下代码中的符号“菜单”:-
@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; }
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); }
无法解析符号“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!
我不知道执行这些代码块时会发生什么,但我想在手机上运行该应用程序!
采纳答案by dtytomi
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 Projectand Build--> Rebuild Project
构建-->清理项目并 构建-->重建项目
回答by Manikandan K
回答by Neha Sharma
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, menu)
2) 点击 make a menu main.xml file (a new file) 3) Disable your antivirus 4) Run the app
回答by Toni fernandez
With more than 20 years of experiencie i can tell you a very difficult solution for the menu problem on android studio...:
凭借 20 多年的经验,我可以告诉您一个非常困难的解决 android studio 菜单问题的方法...:
*********** Close the project an open it again ************************
*********** 关闭项目并再次打开它 ************************