AndroidAndroidStudio空指针解决之:listview与adapter的使用报空 java.lang.NullPointerException
Posted 程序员小冰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AndroidAndroidStudio空指针解决之:listview与adapter的使用报空 java.lang.NullPointerException相关的知识,希望对你有一定的参考价值。
作者:程序员小冰 (转载请说明出处)
博客地址:http://blog.csdn.net/qq_21376985
长期维护的android项目,里面包括常用功能实现,以及知识点详解,
当然还有Java中的知识点。具体请看github:
https://github.com/QQ986945193/DavidAndroidProjectTools
说明,因为最近在将android中常见的知识点,以及常用功能集中在一个android项目中,方便自己以后再看,并且送给初学者以及工作中的人员,以后遇到某些功能直接拿来用。所以就写了了一下listview与adapter的知识点详解,发现突然报空指针。 java.lang.NullPointerException,错误代码如下:
java.lang.NullPointerException
at android.widget.AbsListView.obtainView(AbsListView.java:2277)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
最后仔细看了一下,原来是adapter中的getView();我直接写了返回为null,所以改完之后,就OK了。
当然如果帮到了你,欢迎点赞。小问题。
以上是关于AndroidAndroidStudio空指针解决之:listview与adapter的使用报空 java.lang.NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章
AndroidAndroidStudio开发工具“Gradle project sync failed. Basic functionality (e.g. editing, debugging)