今天在家练习ListView的时候,遇到一个java.lang.NullPointerException的空指针异常,log如下:
2020-05-10 15:40:29.249 20436-20436/? E/k.myapplicatio: Unknown bits set in runtime_flags: 0x8000
2020-05-10 15:40:29.602 20436-20436/com.hpeak.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hpeak.myapplication, PID: 20436
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference
at com.hpeak.myapplication.MainActivity$MyAdapter.getView(MainActivity.java:72)
at android.widget.AbsListView.obtainView(AbsListView.java:2437)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1423)
at android.widget.ListView.onMeasure(ListView.java:1329)
at android.view.View.measure(View.java:25253)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6891)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1204)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:723)
at android.view.View.measure(View.java:25253)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6891)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25253)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6891)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25253)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6891)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:851)
at android.view.View.measure(View.java:25253)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3419)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2124)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2426)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2008)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1036)
at android.view.Choreographer.doCallbacks(Choreographer.java:859)
at android.view.Choreographer.doFrame(Choreographer.java:794)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1021)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:247)
at android.app.ActivityThread.main(ActivityThread.java:8263)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:511)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
根据log信息依次定位到下图所示代码处:
原创文章 13获赞 1访问量 850
关注
私信
展开阅读全文
作者:HPeak