android - Error in doBackground AsyncTask? -


i keep getting error in doinbackground()

07-20 21:05:20.859: error/androidruntime(3289): java.lang.runtimeexception: error occured while executing doinbackground()   07-20 21:05:20.859: error/androidruntime(3289): caused by: android.view.viewroot$calledfromwrongthreadexception: original thread created view hierarchy can touch views. 

here asynctask method.

                private class mytask extends asynctask<void, void, void>{                   @override                 protected void doinbackground(void... arg0) {try {                             getimages();                             log.v("mytask", "image 1 retreived");                             getimage2();                             log.v("mytask", "image 2 retreived");                             getimage3();                             log.v("mytask", "image 3 retreived");                             getimage4();                             log.v("mytask", "image 4 retreived");                         } catch (ioexception e) {                             log.e("mainmenu retreive image", "image retreival failed");                             e.printstacktrace();                         }                     return null;                 }                  protected void onpostexecute(){                     ((gallery) findviewbyid(r.id.gallery))                             .setadapter(new imageadapter(mainmenu.this));                     return null;                  }                          }  } 

and still holding ui reason. ui doesnt appear till after done.

here oncreate() execute asynctask.

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);   mytask mytask = new mytask();      mytask.execute();  } 

you cannot manipulate ui while not in ui thread.

asynctask documentation

i going go out on limb , guess time consuming call getimages(). if case, these method calls should happen in doinbackground() method, , code have in doinbackground() method should moved onpostexecute() method.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -