我的应用程序在某些用户的某些设备上崩溃,但我无法重现它。但我可以看到崩溃报告。我有listview在多个地方使用自定义ArrayAdapter(扩展android.widget.ArrayAdapter)。我不知道它发生在哪里以及如何发生。 崩溃日志说NullPointerException但没有指出它在我的代码中实际发生的位置。有人请帮我解决这个问题。这是日志
java.lang.NullPointerException
at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
at android.widget.HeaderViewListAdapter.getCount(HeaderViewListAdapter.java:132)
at android.widget.ListView.onMeasure(ListView.java:1155)
at android.view.View.measure(View.java:17387)
at android.support.v4.widget.SwipeRefreshLayout.onMeasure(SwipeRefreshLayout.java:353)
at android.view.View.measure(View.java:17387)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17387)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:17387)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:762)
at android.view.View.measure(View.java:17387)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17387)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
at android.view.View.measure(View.java:17387)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
at android.view.View.measure(View.java:17387)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2214)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1351)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1550)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1235)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6472)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
感谢Blackbelt的回答。这就是问题背后的确切原因。我传递给数组适配器的超级构造函数的对象数组为null。我将它保存在静态数组中,并且在某些情况下它以某种方式变为null。再次初始化数组解决了我的问题。