android - Retrieve and parse JSON from multiple URLs and add to listview -


i started learning android week ago , decided write simple android application website bhooka.in. used koush/ion api retrieve json data url.

here's problem - have single json file, containing multiple json urls. tried retrieve jsons in loop, doesn't seem work. here's code:

future<jsonobject> loading;  private void load() {     // don't attempt load more if load in progress     if (loading != null && !loading.isdone() && !loading.iscancelled())         return;      // load tweets     string url = "http://bhooka.in/web_services_json_helper.php?mode=fetch_locations&user_agent=in.bhooka.bhooka&city_id=4";     loading = ion.with(this)             .load(url)             .asjsonobject()             .setcallback(new futurecallback<jsonobject>() {                 @override                 public void oncompleted(exception e, jsonobject result) {                     // called onto ui thread, no activity.runonuithread or handler.post necessary.                     if (e != null) {                         toast.maketext(getview().getcontext(), "error loading information", toast.length_long).show();                         return;                     }                     jsonarray locationslist = result.getasjsonarray("locations");                     // add tweets                     (int = 0; < locationslist.size(); i++) {                         try {                             jsonobject temp = ion.with(getview().getcontext())                                     .load("http://bhooka.in/web_services_json_helper.php?mode=fetch_loc_info&user_agent=in.bhooka.bhooka&loc_id=" + locationslist.get(i).getasjsonobject().get("post_id").getasstring())                                     .asjsonobject().get();                             placearrayadapter.add(temp.get("loc_info").getasjsonobject());                         }                         catch (exception ex)                         {                             ex.printstacktrace();                         }                                  /* tried approach - doesn't work                                 .setcallback(new futurecallback<jsonobject>() {                                     @override                                     public void oncompleted(exception e, jsonobject result) {                                         // called onto ui thread, no activity.runonuithread or handler.post necessary.                                         if (e != null) {                                             toast.maketext(getview().getcontext(), "error loading information", toast.length_long).show();                                             return;                                         }                                         placearrayadapter.add(result.get("loc_info").getasjsonobject());                                     }                                 });*/                     }                 }             }); } 

the application opens , freezes. i've tried asynchronous approach using callbacks, shows 1 or 2 entries in listview , crashes. please tell me i'm doing wrong?

thanks lot.

edit: suggested, here's logcat:

07-14 17:02:11.851  20332-20332/? d/dalvikvm﹕ late-enabling checkjni 07-14 17:02:11.867  20332-20338/? d/dalvikvm﹕ debugger has detached; object registry had 1 entries 07-14 17:02:12.206  20332-20332/? i/adreno-egl﹕ <qegldrvapi_eglinitialize:410>: egl 1.4 qualcomm build: au_linux_android_lnx.la.3.5.1_rb1.04.04.02.048.018_msm8610_lnx.la.3.5.1_rb1__release_au ()     opengl es shader compiler version: e031.24.00.08     build date: 03/07/14 fri     local branch:     remote branch: quic/lnx.la.3.5.1_rb1.1     local patches: none     reconstruct branch: au_linux_android_lnx.la.3.5.1_rb1.04.04.02.048.018 + f2fd134 +  nothing 07-14 17:02:12.244  20332-20332/? d/openglrenderer﹕ enabling debug mode 0 07-14 17:02:14.469  20332-20364/in.bhooka.bhooka d/dalvikvm﹕ trying load lib /data/app-lib/in.bhooka.bhooka-2/libgmscore.so 0x41d995f0 07-14 17:02:14.470  20332-20364/in.bhooka.bhooka e/dalvikvm﹕ dlopen("/data/app-lib/in.bhooka.bhooka-2/libgmscore.so") failed: dlopen failed: library "/data/app-lib/in.bhooka.bhooka-2/libgmscore.so" not found 07-14 17:02:14.470  20332-20364/in.bhooka.bhooka e/providerinstaller﹕ unable load native code /data/app-lib/in.bhooka.bhooka-2/libgmscore.so 07-14 17:02:14.470  20332-20364/in.bhooka.bhooka d/dalvikvm﹕ trying load lib /data/app-lib/com.google.android.gms-2/libgmscore.so 0x41d995f0 07-14 17:02:14.472  20332-20364/in.bhooka.bhooka d/dalvikvm﹕ added shared lib /data/app-lib/com.google.android.gms-2/libgmscore.so 0x41d995f0 07-14 17:02:14.472  20332-20364/in.bhooka.bhooka d/dalvikvm﹕ no jni_onload found in /data/app-lib/com.google.android.gms-2/libgmscore.so 0x41d995f0, skipping init 07-14 17:02:14.474  20332-20364/in.bhooka.bhooka e/providerinstaller﹕ libgmscore version mismatch (0 vs. 7574) 07-14 17:02:14.474  20332-20364/in.bhooka.bhooka w/ionconscrypt﹕ conscrypt initialization failed. 07-14 17:02:44.955  20332-20364/in.bhooka.bhooka d/dalvikvm﹕ gc_for_alloc freed 3066k, 29% free 7930k/11072k, paused 37ms, total 47ms 07-14 17:02:45.008  20332-20332/in.bhooka.bhooka d/androidruntime﹕ shutting down vm 07-14 17:02:45.008  20332-20332/in.bhooka.bhooka w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x415dad40) 07-14 17:02:45.010  20332-20332/in.bhooka.bhooka e/androidruntime﹕ fatal exception: main     process: in.bhooka.bhooka, pid: 20332     java.lang.nullpointerexception             @ in.bhooka.bhooka.mainactivity$1.oncompleted(mainactivity.java:73)             @ in.bhooka.bhooka.mainactivity$1.oncompleted(mainactivity.java:67)             @ com.koushikdutta.async.future.simplefuture.handlecallbackunlocked(simplefuture.java:107)             @ com.koushikdutta.async.future.simplefuture.setcomplete(simplefuture.java:141)             @ com.koushikdutta.async.future.simplefuture.setcomplete(simplefuture.java:124)             @ com.koushikdutta.ion.ionrequestbuilder$1.run(ionrequestbuilder.java:244)             @ com.koushikdutta.async.asyncserver$runnablewrapper.run(asyncserver.java:57)             @ android.os.handler.handlecallback(handler.java:733)             @ android.os.handler.dispatchmessage(handler.java:95)             @ android.os.looper.loop(looper.java:136)             @ android.app.activitythread.main(activitythread.java:5086)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601)             @ dalvik.system.nativestart.main(native method) 

instead use retrofit , jackson converter locations . code since code complex. these best combination deal urls


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -