java - Android: app crashes at onTaskCompleted after app is closed -


i doing asynchronous tasks http fetch data.

when close app in middle of asynchronous operation, nullpointerexception error. seems happening because asynchronous task being competed , ontaskcompleted called; app closed.

does know how handle this?

i'm running android studio, android version 4.4.2. galaxy s4.

java.lang.nullpointerexception         @ com.example.lu.seed_2.tabs.tab4$3.ontaskcompleted(tab4.java:174)         @ com.example.lu.seed_2.articleasync.onpostexecute(articleasync.java:36)         @ com.example.lu.seed_2.articleasync.onpostexecute(articleasync.java:11)         @ android.os.asynctask.finish(asynctask.java:632)         @ android.os.asynctask.access$600(asynctask.java:177)         @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645)         @ android.os.handler.dispatchmessage(handler.java:102)         @ android.os.looper.loop(looper.java:157)         @ android.app.activitythread.main(activitythread.java:5356)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:515)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1265)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1081)         @ dalvik.system.nativestart.main(native method) 

as requested, here ontaskcomplete code

articles = convertjsontoarticles(httpresult.getbody()); articleadapter = new articleadapter(getactivity().getapplicationcontext(), articles);  //<-- app crashes here listview = (listview) getactivity().findviewbyid(r.id.mobile_list4); listview.setadapter(articleadapter); listview.setonitemclicklistener(new adapterview.onitemclicklistener() {     @override     public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {         intent intent = new intent(getactivity().getapplication(), webviewactivity.class);         intent.putextra("_id", articles.get(i).getid());         startactivity(intent);     } }); listview.setonscrolllistener(new abslistview.onscrolllistener() {     @override     public void onscrollstatechanged(abslistview abslistview, int scrollstate) {      }      @override     public void onscroll(abslistview abslistview, int firstvisibleitem, int visibleitemcount, int totalitemcount) {         int itemsleftcount = totalitemcount - firstvisibleitem;          if (itemsleftcount > 8) {             return;         }          if (isloadingmore == true) {             return;         }         loadmorearticles();     } }); listview.addfooterview(footerview); shownotloading(); v.refreshcomplete(); 

maybe should cancel tasks in onstop(), , check if cancelled in doinbackground() if it's in loop. check null references.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -