本人新手,望解答
謝謝
10-13 19:53:37.732: E/AndroidRuntime(12285): FATAL EXCEPTION: main
10-13 19:53:37.732: E/AndroidRuntime(12285): Process: com.example.mydemo, PID: 12285
10-13 19:53:37.732: E/AndroidRuntime(12285): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.example.mydemo.SubFragment1$MyTask.onPostExecute(SubFragment1.java:131)
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.example.mydemo.SubFragment1$MyTask.onPostExecute(SubFragment1.java:1)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.AsyncTask.finish(AsyncTask.java:632)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.AsyncTask.access$600(AsyncTask.java:177)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.Handler.dispatchMessage(Handler.java:102)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.Looper.loop(Looper.java:155)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.app.ActivityThread.main(ActivityThread.java:5696)
10-13 19:53:37.732: E/AndroidRuntime(12285): at java.lang.reflect.Method.invoke(Native Method)
10-13 19:53:37.732: E/AndroidRuntime(12285): at java.lang.reflect.Method.invoke(Method.java:372)
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
代碼如下
10-13 19:53:37.732: E/AndroidRuntime(12285): FATAL EXCEPTION: main
10-13 19:53:37.732: E/AndroidRuntime(12285): Process: com.example.mydemo, PID: 12285
10-13 19:53:37.732: E/AndroidRuntime(12285): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.example.mydemo.SubFragment1$MyTask.onPostExecute(SubFragment1.java:131)
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.example.mydemo.SubFragment1$MyTask.onPostExecute(SubFragment1.java:1)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.AsyncTask.finish(AsyncTask.java:632)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.AsyncTask.access$600(AsyncTask.java:177)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.Handler.dispatchMessage(Handler.java:102)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.os.Looper.loop(Looper.java:155)
10-13 19:53:37.732: E/AndroidRuntime(12285): at android.app.ActivityThread.main(ActivityThread.java:5696)
10-13 19:53:37.732: E/AndroidRuntime(12285): at java.lang.reflect.Method.invoke(Native Method)
10-13 19:53:37.732: E/AndroidRuntime(12285): at java.lang.reflect.Method.invoke(Method.java:372)
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
10-13 19:53:37.732: E/AndroidRuntime(12285): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
這句話很明白的告訴了你setAdapter的調用者為空 也就是listview 是null;
查下是否沒初始化,或者是因為view.findViewById少寫了view.引起。