I am using an AsyncTask to get the data and then loading it into a ListView. My code is :
AsyncTaskTwitterFeeds asyncTaskTwitterFeeds = new AsyncTaskTwitterFeeds(TwitterFeedsActivity.this);
asyncTaskTwitterFeeds.execute("");
loadList();
In the above code, once AsyncTask is executed, the flow, comes to loadlist() method and the program crashes. The reason I found was that the array which is used in the Adapter is still being populated. I want to know that how I can hold once AsyncTask is executed and only when its completed then flow should go to loadlist() method. Here is the LogCat error:
02-25 18:50:25.879: E/AndroidRuntime(19851): FATAL EXCEPTION: main
02-25 18:50:25.879: E/AndroidRuntime(19851): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cubix.twitterfeed/com.cubix.twitterfeed.TwitterFeedsActivity}: java.lang.NullPointerException
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.os.Looper.loop(Looper.java:143)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.ActivityThread.main(ActivityThread.java:4196)
02-25 18:50:25.879: E/AndroidRuntime(19851): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 18:50:25.879: E/AndroidRuntime(19851): at java.lang.reflect.Method.invoke(Method.java:507)
02-25 18:50:25.879: E/AndroidRuntime(19851): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-25 18:50:25.879: E/AndroidRuntime(19851): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-25 18:50:25.879: E/AndroidRuntime(19851): at dalvik.system.NativeStart.main(Native Method)
02-25 18:50:25.879: E/AndroidRuntime(19851): Caused by: java.lang.NullPointerException
02-25 18:50:25.879: E/AndroidRuntime(19851): at java.util.Arrays$ArrayList.<init>(Arrays.java:47)
02-25 18:50:25.879: E/AndroidRuntime(19851): at java.util.Arrays.asList(Arrays.java:169)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:125)
02-25 18:50:25.879: E/AndroidRuntime(19851): at com.cubix.twitterfeed.TwitterAdapter.<init>(TwitterAdapter.java:17)
02-25 18:50:25.879: E/AndroidRuntime(19851): at com.cubix.twitterfeed.TwitterFeedsActivity.loadList(TwitterFeedsActivity.java:48)
02-25 18:50:25.879: E/AndroidRuntime(19851): at com.cubix.twitterfeed.TwitterFeedsActivity.onCreate(TwitterFeedsActivity.java:30)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
02-25 18:50:25.879: E/AndroidRuntime(19851): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
02-25 18:50:25.879: E/AndroidRuntime(19851): ... 11 more
AsyncTaskhas a methodonPostExecute()that executes on the main UI thread after theAsyncTaskhas finished its job in the methoddoInBackground(). You could use that method to populate the list ifloadList()is called to populate the list with the results from theAsyncTask.