android-弹出菜单onitemclick错误

android-Popup menu onitemclick error

我正在尝试使用 intent 将每个弹出菜单项指向另一个 activity,但我收到如下所示的错误:

这是我的 java 弹出菜单代码:

popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    public boolean onMenuItemClick(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.one:
                Intent i = new Intent(Cihazlar.this,MainActivity.class);
                startActivity(i);
                return true;

            case R.id.two:
                Intent i2 = new Intent(Cihazlar.this,Kampanya.class);
                startActivity(i2);
                return true;


        }
        return true;
    }
});

这是弹出菜单xml:

<menu xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/tools">

<item
    android:id="@+id/one"
    androclass:title="Senin Dünyan" />

<item
    android:id="@+id/two"
    androclass:title="Destek" />

<item
    android:id="@+id/three"
    androclass:title="Sıkça Sorulan Sorular" />

那么为什么我会收到此错误?任何帮助将不胜感激。

兄弟,你在清单中声明了吗post你的清单代码

问题不在 运行 时间。这是编译时错误。因此,如果错误类似于 resource not found,则错误是在导入 R 包时或 menu.xml.

中的错误

但是 menu.xml 看起来不错,所以我认为,主要问题是 R.java 导入。检查您是否没有导入 com.android.R。应该是你的<package_name>.R。 即使这没问题,那么您的资源也没有完全编译。其他资源文件(.xml 文件)

可能有一些错误

可以尝试的最后一件事是重建您的应用程序,然后检查

编辑

我认为 menu.xml 文件本身有错误。试试下面的代码,除非你做了一些定制的东西-

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

<item
    android:id="@+id/one"
    android:title="Senin Dünyan" />

<item
    android:id="@+id/two"
    androclass:title="Destek" />

<item
    android:id="@+id/three"
    android:title="Sıkça Sorulan Sorular" />