map - Android AsyncTask error while adding items to GoogleMap -


i want load coordinates file , add shapes map in async task. getting error, , don't know why. here code:

   private class shploading extends asynctask<googlemap, void, string> {           progressdialog dialog;            @override           protected string doinbackground(googlemap... params) {                                   shpreader shpread = new shpreader();                 googlemap map = params[0];                 try {                     shpread.reading();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } catch (invalidshapefileexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                 for(latlng : shpread.points())                      map.addmarker(new markeroptions()                     .position(a)                     .draggable(false));                  int = 0;                 for(list<latlng> a: shpread.lines()){                     map.addpolyline(new polylineoptions()                     .addall(a)                     .width(3)                     .color(color.red));                   }                  for(list<latlng> a: shpread.polygons()){                     map.addpolygon(new polygonoptions()                     .addall(a)                     .strokewidth(3)                     .strokecolor(color.red)                     .fillcolor(0x3f00ff00));                  }                 return "done";           }                @override           protected void onpreexecute() {                   dialog = new progressdialog(measuring.this);                           dialog.setmessage("kraunama...");                   dialog.setindeterminate(true);                   dialog.setcancelable(false);                   dialog.show();           }            @override           protected void onprogressupdate(void... values) {           }            @override           protected void onpostexecute(string result) {                                dialog.dismiss();           }                          }    

and how execute code:

shploading load = new shploading(); load.execute(mmap);   

mmap googlemap variable. if add doinbackground code onpostexecute method , change variable map global mmap eveything working, want task in background , show loading dialog @ same time.

here logcat:

 08-26 11:10:52.368: e/androidruntime(11099): fatal exception:  asynctask #1   08-26 11:10:52.368: e/androidruntime(11099):  java.lang.runtimeexception: error occured while executing  doinbackground()   08-26 11:10:52.368: e/androidruntime(11099):   @  android.os.asynctask$3.done(asynctask.java:299) 08-26 11:10:52.368:  e/androidruntime(11099):   @  java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273)  08-26 11:10:52.368: e/androidruntime(11099):   @  java.util.concurrent.futuretask.setexception(futuretask.java:124)  08-26 11:10:52.368: e/androidruntime(11099):   @  java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307)  08-26 11:10:52.368: e/androidruntime(11099):   @  java.util.concurrent.futuretask.run(futuretask.java:137) 08-26  11:10:52.368: e/androidruntime(11099):     @  android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 08-26  11:10:52.368: e/androidruntime(11099):     @  java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076)  08-26 11:10:52.368: e/androidruntime(11099):   @  java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569)  08-26 11:10:52.368: e/androidruntime(11099):   @  java.lang.thread.run(thread.java:856) 08-26 11:10:52.368:  e/androidruntime(11099): caused by: java.lang.illegalstateexception:  not on main thread 08-26 11:10:52.368: e/androidruntime(11099):     @ maps.ar.p.b(unknown source) 08-26 11:10:52.368:  e/androidruntime(11099):   @ maps.al.g.b(unknown source) 08-26  11:10:52.368: e/androidruntime(11099):     @ maps.ag.an.a(unknown  source) 08-26 11:10:52.368: e/androidruntime(11099):   @  bkw.ontransact(sourcefile:137) 08-26 11:10:52.368:  e/androidruntime(11099):   @  android.os.binder.transact(binder.java:326) 08-26 11:10:52.368:  e/androidruntime(11099):   @  com.google.android.gms.maps.internal.igooglemapdelegate$a$a.addpolyline(unknown  source) 08-26 11:10:52.368: e/androidruntime(11099):   @  com.google.android.gms.maps.googlemap.addpolyline(unknown source)  08-26 11:10:52.368: e/androidruntime(11099):   @  com.es.map.measuring$shploading.doinbackground(measuring.java:1165)  08-26 11:10:52.368: e/androidruntime(11099):   @  com.es.map.measuring$shploading.doinbackground(measuring.java:1) 08-26  11:10:52.368: e/androidruntime(11099):     @  android.os.asynctask$2.call(asynctask.java:287) 08-26 11:10:52.368:  e/androidruntime(11099):   @  java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305)  08-26 11:10:52.368: e/androidruntime(11099):   ... 5 more 08-26  11:11:00.453: e/windowmanager(11099): activity com.es.map.measuring  has leaked window  com.android.internal.policy.impl.phonewindow$decorview@42229e30  added here 08-26 11:11:00.453: e/windowmanager(11099):  android.view.windowleaked: activity com.es.map.measuring has leaked  window com.android.internal.policy.impl.phonewindow$decorview@42229e30  added here 08-26 11:11:00.453:  e/windowmanager(11099):    @  android.view.viewrootimpl.<init(viewrootimpl.java:403) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.view.windowmanagerimpl.addview(windowmanagerimpl.java:311)  08-26 11:11:00.453: e/windowmanager(11099):    @  android.view.windowmanagerimpl.addview(windowmanagerimpl.java:224)  08-26 11:11:00.453: e/windowmanager(11099):    @  android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:149)  08-26 11:11:00.453: e/windowmanager(11099):    @  android.view.window$localwindowmanager.addview(window.java:554) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.app.dialog.show(dialog.java:277) 08-26 11:11:00.453:  e/windowmanager(11099):    @  com.es.map.measuring$shploading.onpreexecute(measuring.java:1195)  08-26 11:11:00.453: e/windowmanager(11099):    @  android.os.asynctask.executeonexecutor(asynctask.java:586) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.os.asynctask.execute(asynctask.java:534) 08-26 11:11:00.453:  e/windowmanager(11099):    @  com.es.map.measuring.onoptionsitemselected(measuring.java:566) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.app.activity.onmenuitemselected(activity.java:2629) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.support.v4.app.fragmentactivity.onmenuitemselected(fragmentactivity.java:366)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.policy.impl.phonewindow.onmenuitemselected(phonewindow.java)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.view.menu.menubuilder.dispatchmenuitemselected(menubuilder.java:735)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.view.menu.menuitemimpl.invoke(menuitemimpl.java:149)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.view.menu.menubuilder.performitemaction(menubuilder.java:874)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.view.menu.iconmenuview.invokeitem(iconmenuview.java:468)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.view.menu.iconmenuitemview.performclick(iconmenuitemview.java:126)  08-26 11:11:00.453: e/windowmanager(11099):    @  android.view.view$performclick.run(view.java:17298) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.os.handler.handlecallback(handler.java:615) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.os.handler.dispatchmessage(handler.java:92) 08-26  11:11:00.453: e/windowmanager(11099):  @  android.os.looper.loop(looper.java:137) 08-26 11:11:00.453:  e/windowmanager(11099):    @  android.app.activitythread.main(activitythread.java:4921) 08-26  11:11:00.453: e/windowmanager(11099):  @  java.lang.reflect.method.invokenative(native method) 08-26  11:11:00.453: e/windowmanager(11099):  @  java.lang.reflect.method.invoke(method.java:511) 08-26 11:11:00.453:  e/windowmanager(11099):    @  com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038)  08-26 11:11:00.453: e/windowmanager(11099):    @  com.android.internal.os.zygoteinit.main(zygoteinit.java:805) 08-26  11:11:00.453: e/windowmanager(11099):  @  dalvik.system.nativestart.main(native method) 

and maybe it's not way load coordinates file , add them map? maybe there better way this?

sorry can not change ui component background thread must write map operation in uithread.

your solution within existing code :

private handler mhandler = new handler();      private class shploading extends asynctask<googlemap, void, string> {         progressdialog dialog;          @override         protected string doinbackground(googlemap... params) {                                 shpreader shpread = new shpreader();               googlemap map = params[0];               try {                   shpread.reading();               } catch (ioexception e) {                   // todo auto-generated catch block                   e.printstacktrace();               } catch (invalidshapefileexception e) {                   // todo auto-generated catch block                   e.printstacktrace();               }                mhandler.post(new runnable() {                 public void run() {                     for(latlng : shpread.points())                          map.addmarker(new markeroptions()                         .position(a)                         .draggable(false));                      int = 0;                     for(list<latlng> a: shpread.lines()){                         map.addpolyline(new polylineoptions()                         .addall(a)                         .width(3)                         .color(color.red));                       }                      for(list<latlng> a: shpread.polygons()){                         map.addpolygon(new polygonoptions()                         .addall(a)                         .strokewidth(3)                         .strokecolor(color.red)                         .fillcolor(0x3f00ff00));                      }                 }             });               return "done";         }              @override         protected void onpreexecute() {                 dialog = new progressdialog(measuring.this);                         dialog.setmessage("kraunama...");                 dialog.setindeterminate(true);                 dialog.setcancelable(false);                 dialog.show();         }          @override         protected void onprogressupdate(void... values) {         }          @override         protected void onpostexecute(string result) {                              dialog.dismiss();         }                        }    

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -