2016-04-25 60 views
0

我想直接的每个弹出菜单项到另一个活动使用的意图,但我得到如下错误:Android的弹出菜单onitemclick错误

error

这是弹出我的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" /> 

那么,为什么我得到这个错误?任何帮助将不胜感激。

+0

请检查导入语句中R的包名称。 – Raghavendra

+0

清除并重新构建您的项目。 –

+0

你可以发布你的进口报表吗? – Raghavendra

回答

0

问题不是在运行时。这是编译时错误。因此,如果错误类似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" /> 
+0

谢谢你man.You救了我的生命:D –

+0

伟大的...!玩的开心 –

0

兄弟具有u宣布它在清单PLZ发表您的清单代码