Reputation: 425
So this program I am trying to write is acting weird, what it does is, it downloads a JSON file from a site, parses it, then puts all the items into a ListView
. The weird thing about it is that when I run the debugger I see that it successfully populates the list on the screen but when I try to run it normally it immediately crashes. This is the statements I am getting from 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)
Thanks for any help!
Upvotes: 1
Views: 85
Reputation: 46
CustomAdapter.java file 61 line error. Custom Adapter to create a place to hand over parameters Make sure that your list. present in the adapter occurs nullpointEexception'm getCount method.
Upvotes: 2
Reputation: 425
I was telling it to setListAdapter in onCreate right after I executed my AsyncTask that was downloading the JSON. So I fixed it by setting the list adapter in onPostExecute. Wow that was a stupid mistake. But thanks to @Tamil Selvan his question helped me realize my fault!
Upvotes: 1