Android onCreateContextMenu-NPE

Android onCreateContextMenu-NPE,android,nullpointerexception,contextmenu,Android,Nullpointerexception,Contextmenu,我正在开发一个代码,在长时间单击列表视图项时,应该会弹出一个上下文菜单。这以前是有效的,但不知道为什么现在是NPE。请参阅下面的代码并提出建议 public void displayImages(){ //some other functionality imageAdapter = new GoodAdapter(this, imageBeanArray); list.setAdapter(imageAdapter); list.setChoiceMode(ListView.

我正在开发一个代码,在长时间单击列表视图项时,应该会弹出一个上下文菜单。这以前是有效的,但不知道为什么现在是NPE。请参阅下面的代码并提出建议

public void displayImages(){
//some other functionality
 imageAdapter = new GoodAdapter(this, imageBeanArray);
    list.setAdapter(imageAdapter);
    list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    registerForContextMenu(list);
}

 @Override
public void onCreateContextMenu(ContextMenu menu, View v,
                                ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle("Options");
    menu.add(0, v.getId(), 0, "Rename");
    menu.add(0,v.getId(),0,"Delete");
}

 @Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
    final ImageBean imageBean = imageBeanArray.get(info.position);
    final int selectedImageId= imageBean.getId();

   if(item.getTitle()=="Rename") {//Do some thing}
   else if (item.getTitle()=="Rename") {//Do some thing else}
 }
列表视图的布局声明:

<?xml version="1.0" encoding="utf-8"?>

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/menu"
    android:background="@color/white"
    android:choiceMode="multipleChoice"
    android:cacheColorHint="#00000000"
    android:scrollbars="none" />

似乎无法将
setChoiceMode(ListView.CHOICE\u MODE\u MULTIPLE\u MODE)
与关联菜单结合使用。由于您的布局XML已经(正确地)提供了
android:choiceMode=“multipleechoice”
,您可以安全地删除对
CHOICE\u MODE\u MULTIPLE\u model
的代码覆盖。您可以提供ListView的布局声明吗?@PaulLammertsma:请查找布局XML代码。很抱歉,我无法将其添加为XML代码。不知道为什么。看起来你是对的。删除覆盖后,代码现在运行良好。谢谢你,巴德。但是,这背后有什么逻辑吗?只是想知道,难道不存在这样一种情况:用户可以选择多个项目(复选框),而同一个列表可以在每个列表项目的顶部设置contextmenu吗?对此有什么想法吗。。。
E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.kittu.ClientLync, PID: 30281
    java.lang.NullPointerException
            at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2694)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2619)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
            at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
            at android.view.View.startActionMode(View.java:4752)
            at android.widget.AbsListView.performLongPress(AbsListView.java:3538)
            at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:3494)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5487)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)