android - IllegalStateException map size should not be 0 -
this question has answer here:
i have mapfragment
displays map
if user goes away activity (or device goes sleep) map comes onresume
gets called , move map marker.
however when move camera exception
07-23 16:28:42.725: e/androidruntime(19095): java.lang.runtimeexception: unable resume activity {ecm2.android/ecm2.android.emgnotemapactivity}: java.lang.illegalstateexception: map size should not 0. likely, layout has not yet occured map view. 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread.performresumeactivity(activitythread.java:2742) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread.handleresumeactivity(activitythread.java:2771) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2235) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread.access$600(activitythread.java:141) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 07-23 16:28:42.725: e/androidruntime(19095): @ android.os.handler.dispatchmessage(handler.java:99) 07-23 16:28:42.725: e/androidruntime(19095): @ android.os.looper.loop(looper.java:137) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread.main(activitythread.java:5041) 07-23 16:28:42.725: e/androidruntime(19095): @ java.lang.reflect.method.invokenative(native method) 07-23 16:28:42.725: e/androidruntime(19095): @ java.lang.reflect.method.invoke(method.java:511) 07-23 16:28:42.725: e/androidruntime(19095): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 07-23 16:28:42.725: e/androidruntime(19095): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 07-23 16:28:42.725: e/androidruntime(19095): @ dalvik.system.nativestart.main(native method) 07-23 16:28:42.725: e/androidruntime(19095): caused by: java.lang.illegalstateexception: map size should not 0. likely, layout has not yet occured map view. 07-23 16:28:42.725: e/androidruntime(19095): @ maps.as.i.b(unknown source) 07-23 16:28:42.725: e/androidruntime(19095): @ maps.ah.w.a(unknown source) 07-23 16:28:42.725: e/androidruntime(19095): @ maps.ah.s.a(unknown source) 07-23 16:28:42.725: e/androidruntime(19095): @ maps.ah.an.b(unknown source) 07-23 16:28:42.725: e/androidruntime(19095): @ bgc.ontransact(sourcefile:92) 07-23 16:28:42.725: e/androidruntime(19095): @ android.os.binder.transact(binder.java:310) 07-23 16:28:42.725: e/androidruntime(19095): @ com.google.android.gms.maps.internal.igooglemapdelegate$a$a.animatecamera(unknown source) 07-23 16:28:42.725: e/androidruntime(19095): @ com.google.android.gms.maps.googlemap.animatecamera(unknown source) 07-23 16:28:42.725: e/androidruntime(19095): @ ecm2.android.fragments.emgmap.centeronnote(emgmap.java:340) 07-23 16:28:42.725: e/androidruntime(19095): @ ecm2.android.fragments.emgmap.fetchmapsettings(emgmap.java:283) 07-23 16:28:42.725: e/androidruntime(19095): @ ecm2.android.fragments.emgmap.onresume(emgmap.java:289) 07-23 16:28:42.725: e/androidruntime(19095): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:917) 07-23 16:28:42.725: e/androidruntime(19095): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1080) 07-23 16:28:42.725: e/androidruntime(19095): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1062) 07-23 16:28:42.725: e/androidruntime(19095): @ android.support.v4.app.fragmentmanagerimpl.dispatchresume(fragmentmanager.java:1820) 07-23 16:28:42.725: e/androidruntime(19095): @ android.support.v4.app.fragmentactivity.onpostresume(fragmentactivity.java:412) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activity.performresume(activity.java:5195) 07-23 16:28:42.725: e/androidruntime(19095): @ android.app.activitythread.performresumeactivity(activitythread.java:2732) 07-23 16:28:42.725: e/androidruntime(19095): ... 12 more
this camera movement on onresume
if(map != null && northeast != null && southwest != null){ map.animatecamera(cameraupdatefactory.newlatlngbounds(new latlngbounds(southwest,northeast),10)); }else if(map != null && centerpoint != null){ cameraposition position = new cameraposition.builder() .target(centerpoint).zoom(17).build(); map.animatecamera(cameraupdatefactory.newcameraposition(position)); }
if take out camera movement not crash not go point of moved away or something.
i check make sure map
not null not know causing error?
caused by: java.lang.illegalstateexception: map size should not 0. likely, layout has not yet occured map view.
this should clear enough. cannot call
map.animatecamera(cameraupdatefactory.newlatlngbounds(new latlngbounds(southwest,northeast),10));
before layout complete. need use 3 param version instead.
see documentation here: newlatlngbounds
aternatively may listen layout complete instead of calling code in onresume
.
Comments
Post a Comment