-5

我现在不明白这个 LogCat 条目的含义。有人能帮我吗?

12-26 18:33:09.651: E/AndroidRuntime(26038): FATAL EXCEPTION: main
12-26 18:33:09.651: E/AndroidRuntime(26038): java.lang.NullPointerException
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.AbsListView.obtainView(AbsListView.java:2090)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1485)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.ListView.onMeasure(ListView.java:1348)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.View.measure(View.java:12937)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:579)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:392)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.View.measure(View.java:12937)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5045)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.View.measure(View.java:12937)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.View.measure(View.java:12937)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5045)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2180)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.View.measure(View.java:12937)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1227)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2700)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.os.Looper.loop(Looper.java:156)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at android.app.ActivityThread.main(ActivityThread.java:5099)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at java.lang.reflect.Method.invokeNative(Native Method)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at java.lang.reflect.Method.invoke(Method.java:511)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-26 18:33:09.651: E/AndroidRuntime(26038):    at dalvik.system.NativeStart.main(Native Method)
12-26 18:33:11.691: D/Process(26038): killProcess, pid=26038
12-26 18:33:11.691: D/Process(26038): dalvik.system.VMStack.getThreadStackTrace(Native Method)
12-26 18:33:11.691: D/Process(26038): java.lang.Thread.getStackTrace(Thread.java:599)
12-26 18:33:11.691: D/Process(26038): android.os.Process.killProcess(Process.java:813)
12-26 18:33:11.691: D/Process(26038): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:104)
12-26 18:33:11.701: D/Process(26038): java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
12-26 18:33:11.701: D/Process(26038): java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
12-26 18:33:11.701: D/Process(26038): dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2
java.lang.NullPointerException
    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
ArrayAdapter<Comment> adapter = 
    new ArrayAdapter<Comment>(this, android.R.layout.simple_list_item_1, values);

values至少有一个空对象,你不能有。


您可以阅读源代码并在此处看到这种情况:

T item = getItem(position);
if (item instanceof CharSequence) {
    text.setText((CharSequence)item);
} else {
    text.setText(item.toString()); // Line 394, when item is null this throws an NPE
}
于 2012-12-26T17:38:40.033 回答