简体   繁体   English

Android:菜单无法解析为类型

[英]Android : menu cannot be resolved to a type

This is how I do:我是这样做的:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.game_menu, menu);
    return true;
}

game_menu.xml game_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
      android:title="@string/new_game"/>
<item android:id="@+id/help"
      android:title="@string/help" />
</menu>

But Eclipse keep telling me that menu is not a type... I tried to import R, clean my project and some others things i saw on the.net.但是 Eclipse 一直告诉我菜单不是一种类型...我尝试导入 R,清理我的项目和我在 .net 上看到的其他一些东西。

I cant bypass this problem with that:我不能绕过这个问题:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(Menu.NONE, Menu.FIRST + 1, 5, "??").setIcon(
                android.R.drawable.ic_menu_delete);
        menu.add(Menu.NONE, Menu.FIRST + 2, 2, "??").setIcon(
                android.R.drawable.ic_menu_edit);
        return true; 
    }

Thank you in advance and sorry for my spelling.提前谢谢你,对不起我的拼写。

The xml file must be in the res/menu folder. xml 文件必须在 res/menu 文件夹中。 Also check that you have imported R class with a correct namespace and not android.R还要检查您是否导入了具有正确命名空间的 R class 而不是 android.R

just add import android.view.MenuItem;只需添加 import android.view.MenuItem;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM