I have the following problem:
I display items on a ListView and I want to display a ContextMenu for the item, if the user clicks it. So what I did is, adding an OnItemClickListener with the following code:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view == null) {
return;
}
if (sessionListView == null) {
sessionListView = (SessionListView) findViewById(R.id.sessionlist);
}
if (view != null) {
sessionListViewSelected = position;
sessionListViewSelectedKey = (String) authList.keySet().toArray()[position];
sessionListView.showContextMenuForChild(view);
}
}
Now, SOMETIMES I get following error:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.AdapterView.getPositionForView(AdapterView.java:581)
at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:1926)
at de.trier.infsec.koch.droidsheep.activities.ListenActivity.onItemClick(ListenActivity.java:322)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3513)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Does anybody have an suggestion, what could be the problem for that?
Thanks!!
The problem probably occurs because you are updating ListAdapter from separate thread. You should only mutate UI elements (or classes that UI elements depend on) from UI thread.
Try this to update your data on UI thread: