程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> asynctask-setAdapter時空指針異常

asynctask-setAdapter時空指針異常

編輯:編程綜合問答
setAdapter時空指針異常

本人新手,望解答
謝謝
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.引起。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved