Android: "Expected resource of type menu" 错误

Android: "Expected resource of type menu" error

我在这行代码中遇到错误 "Expected resource of type menu"

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.layout.activity_apps, menu);
    }

但是我的 xml 文件 actvity_apps.xml 只包含菜单标签,没有其他内容

<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<item
    android:id="@+id/menu_configure_locale"
    android:showAsAction="collapseActionView"
    android:title="@string/menu_configure_locale" />

</menu>

有人可以解释发生了什么以及如何修复错误吗?

Can someone explain what is going on

您在 res/layout/ 中放置了一个菜单资源,构建工具不会接受它。

and how to fix the error?

将文件从 res/layout/ 移动到 res/menu/。您可能需要创建 res/menu/ 目录。