开发者

Gridview onClickListerener nullpointer

The code: http://pastebin.com/5bhKULGd

the problem: When you click an item in the gridview, OCLGenre (OnItemClickListener for Genre view) fires an nullPointer at line 123. I'm trying to understand where the nullPointer comes from but can't find it.

The stack:

ERROR/AndroidRuntime(10511): FATAL EXCEPTION: main
 java.lang.NullPointerException
 at com.MMWeb.MMWeb$browse$1.onItemClick(MMWeb.java:123)
 at android.widget.AdapterView.performItemClick(AdapterView.java:284)
 at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
 at android.os.Handler.handleCallback(Handler.java:587)
 at android.os.Handler.dispatchMessage(Handler.java:92)
 at android.os.Looper.loop(Looper.java:123)
 at android.app.ActivityThread.mai开发者_StackOverflown(ActivityThread.java:3683)
 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:839)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 at dalvik.system.NativeStart.main(Native Method)

Anyone got a pointer to where to find the source of this nullPointer?


If you try to access an object which is null. Like the below example.

ClassA  objA;

At this time you have just declared this object but you have not initialized or instantiated it.

When you try to access any property or method in it, it will throw
NullPointerException.


Oke i found my problem By moving the ImageAdapter out of the "browse" class, the "browse" class did not have any reference to the ArrayList 'items'. I could find the problem because, after all, i defined the ArrayList at line 112. However, showGenres() uses a local ArrayList, and the ImageAdapter would put it in "browser.items". Fixed it by removing the local decleration of items on line 145, 154 and 162

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜