http - Android : FATAL EXCEPTION AsyncTask #4 -


my application crash error : it's asynchronous http request collect picture on url.

04-18 14:47:51.336: error/androidruntime(10112): fatal exception: asynctask #4     java.lang.runtimeexception: error occured while executing doinbackground()     @ android.os.asynctask$3.done(asynctask.java:299)     @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273)     @ java.util.concurrent.futuretask.setexception(futuretask.java:124)     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307)     @ java.util.concurrent.futuretask.run(futuretask.java:137)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569)     @ java.lang.thread.run(thread.java:856)     caused by: android.view.viewrootimpl$calledfromwrongthreadexception: original thread created view hierarchy can touch views.     @ android.view.viewrootimpl.checkthread(viewrootimpl.java:4865)     @ android.view.viewrootimpl.invalidatechildinparent(viewrootimpl.java:979)     @ android.view.viewgroup.invalidatechild(viewgroup.java:4306)     @ android.view.view.invalidate(view.java:10519)     @ android.view.view.setflags(view.java:8635)     @ android.view.view.setvisibility(view.java:5647)     @ com.advertising.adactivity.onpause(adactivity.java:122)     @ com.advertising.adactivity.close(adactivity.java:355)     @ com.advertising.adactivity.onimagefailure(adactivity.java:470)     @ com.advertising.http.tasks.imagehttptask.raiseonfailure(imagehttptask.java:74)     @ com.advertising.http.tasks.imagehttptask.doinbackground(imagehttptask.java:52)     @ com.advertising.http.tasks.imagehttptask.doinbackground(imagehttptask.java:20)     @ android.os.asynctask$2.call(asynctask.java:287)     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305)     ... 4 more 

and doinbackground :

    protected bitmap doinbackground(string... urls) {     string urldisplay = urls[0];     bitmap micon11 = null;     httpresponse response;     try {         httpget request = new httpget(urldisplay);         response = client.execute(request);         httpentity entity = response.getentity();         inputstream inputstream = entity.getcontent();         micon11 = bitmapfactory.decodestream(inputstream);         inputstream.close();     } catch (exception e) {         raiseonfailure(e, errortype.ad_error);}     return micon11;} 

edit : inpostexecute/raiseonsuccess/raiseonfailure :

@override protected void onpostexecute(bitmap result) {         bmimage.setimagebitmap(result);     raiseonsuccess(bmimage); }  private void raiseonsuccess(imageview imageview) {     if (this.imagehttpdelegate != null) {         this.imagehttpdelegate.onimagesuccess(imageview);     } else {         logger.d("successfull image received.");     } }  private void raiseonfailure(throwable throwable, errortype errortype) {     if (this.imagehttpdelegate != null) {         this.imagehttpdelegate.onimagefailure(throwable, errortype);     } else {         if (throwable.getmessage() != null) {             logger.d(throwable.getmessage());         }     } } 

can yout me ? don't why crash.

your raiseonfailure method accessing methods on activity should called main thread. try recording error in asynctask , calling raiseonerror in onpostexecute function.

example

private volatile exception merror; protected bitmap doinbackground(string... urls) {     string urldisplay = urls[0];     bitmap micon11 = null;     httpresponse response;     try {         httpget request = new httpget(urldisplay);         response = client.execute(request);         httpentity entity = response.getentity();         inputstream inputstream = entity.getcontent();         micon11 = bitmapfactory.decodestream(inputstream);         inputstream.close();     } catch (exception e) {         merror  = e;         return null;     }     return micon11;     }       @override      protected void onpostexecute(bitmap result) {         if(merror != null) { raiseonfailure(merror, errortype.ad_error); }          else {            bmimage.setimagebitmap(result);            raiseonsuccess(bmimage);         }      } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -