今天给GridView设置数据时一直莫名报空指针,错误信息如下,后来网上搜索查下,才知道知己在adapter的getView()方法里返回的是null,真想给自己一个大嘴巴子,特此记录下这个失误。
1-26 16:48:33.209: E/AndroidRuntime(3169): FATAL EXCEPTION: main
11-26 16:48:33.209: E/AndroidRuntime(3169): java.lang.NullPointerException
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.AbsListView.obtainView(AbsListView.java:2269)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.GridView.onMeasure(GridView.java:1030)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
11-26 16:48:33.209: E/AndroidRuntime(3169): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.View.measure(View.java:15172)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:736)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.Choreographer.doCallbacks(Choreographer.java:566)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.Choreographer.doFrame(Choreographer.java:536)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:722)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.os.Handler.handleCallback(Handler.java:615)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.os.Looper.loop(Looper.java:137)
11-26 16:48:33.209: E/AndroidRuntime(3169): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-26 16:48:33.209: E/AndroidRuntime(3169): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 16:48:33.209: E/AndroidRuntime(3169): at java.lang.reflect.Method.invoke(Method.java:511)
11-26 16:48:33.209: E/AndroidRuntime(3169): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-26 16:48:33.209: E/AndroidRuntime(3169): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-26 16:48:33.209: E/AndroidRuntime(3169): at dalvik.system.NativeStart.main(Native Method)