所以這個節目,我想寫行事怪異,但它是什麼,它的下載從網站JSON文件,分析它,然後將所有物品變成了ListView
。關於它的奇怪的是,當我運行調試我看到它成功地填充屏幕上的名單,但是當我嘗試正常運行它,它立即崩潰。這是我從logcat得到的陳述:我需要幫助破譯這個錯誤,我想填充列表視圖
03-30 22:34:28.115: E/AndroidRuntime(17758): FATAL EXCEPTION: main
03-30 22:34:28.115: E/AndroidRuntime(17758): Process: com.example.listview, PID: 17758
03-30 22:34:28.115: E/AndroidRuntime(17758): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.listview/com.example.listview.Activity_ListView}: java.lang.NullPointerException
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.os.Handler.dispatchMessage(Handler.java:102)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.os.Looper.loop(Looper.java:136)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-30 22:34:28.115: E/AndroidRuntime(17758): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 22:34:28.115: E/AndroidRuntime(17758): at java.lang.reflect.Method.invoke(Method.java:515)
03-30 22:34:28.115: E/AndroidRuntime(17758): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-30 22:34:28.115: E/AndroidRuntime(17758): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-30 22:34:28.115: E/AndroidRuntime(17758): at dalvik.system.NativeStart.main(Native Method)
03-30 22:34:28.115: E/AndroidRuntime(17758): Caused by: java.lang.NullPointerException
03-30 22:34:28.115: E/AndroidRuntime(17758): at com.example.listview.CustomAdapter.getCount(CustomAdapter.java:61)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.widget.ListView.setAdapter(ListView.java:480)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ListActivity.setListAdapter(ListActivity.java:265)
03-30 22:34:28.115: E/AndroidRuntime(17758): at com.example.listview.Activity_ListView.onCreate(Activity_ListView.java:85)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.Activity.performCreate(Activity.java:5231)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-30 22:34:28.115: E/AndroidRuntime(17758): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
感謝您的任何幫助!
當json沒有值或空值時,你是否處理NULLPointerException –
不,但列表不應該爲空......但我猜想有些奇怪的事情可能發生在一次它稱爲null的地方。我會檢查主要活動還是在自定義適配器中? – SketchyTurtle
開始ComponentInfo的活動。 據: 03-30 22:34:28.115:E/AndroidRuntime(17758):了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example.listview/com.example.listview.Activity_ListView}:JAVA。 lang.NullPointerException –