FATAL EXCEPTION: main
Process: com.android.phone, PID: 2026
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:453)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:415)
at android.widget.AbsListView.obtainView(AbsListView.java:2399)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1484)
at android.widget.ListView.onMeasure(ListView.java:1391)
at android.view.View.measure(View.java:23230)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23230)
at com.android.internal.widget.AlertDialogLayout.tryOnMeasure(AlertDialogLayout.java:144)
at com.android.internal.widget.AlertDialogLayout.onMeasure(AlertDialogLayout.java:69)
at android.view.View.measure(View.java:23230)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23230)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23230)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:716)
at android.view.View.measure(View.java:23230)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2775)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1561)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1884)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1476)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7295)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1004)
at android.view.Choreographer.doCallbacks(Choreographer.java:816)
at android.view.Choreographer.doFrame(Choreographer.java:751)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:990)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:217)
at android.app.ActivityThread.main(ActivityThread.java:6868)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
对应代码如下。数据源为getItem。说明adapter对应的ListItem位置的数据是空。
所以根本原因是将空数据放入了ListItem,或者ListItem数据改变,但是没有及时告知adapter,导致adapter认为对应位置还有数据。要找到当时什么应用工作在phone进程来进行优化。
网上找到两个相关的链接,也放在下面。
NullPointerException at android widget ArrayAdapter createViewFromResource - Stack Overflow
https://stackoverflow.com/questions/20170322/nullpointerexception-at-android-widget-arrayadapter-createviewfromresource
--》链接中建议如下:
It would be better if you check if any item is null before adding it to ListView
.
int count = persons.getCount();
Log.d(TAG, String.valueOf(count));
for (int i = 0; i < count; i++) {
/*====== this is where listView is populated =====*/
if(persons.get(i).getDisplayName() != null) {
sListItems.add(persons.get(i).getDisplayName());
}
}
惊现RecyclerView内部Bug???别急,我们慢慢解决它~
http://www.apkbus.com/blog-898535-67963.html
这个链接是定义自己的LayoutManaer,然后onLayoutChildren时try catch异常。