I have a MapFragment
that displays a map
if the user goes away from the activity (or the device goes to sleep) with the map then comes back onResume
gets called and I move the map back to a marker.
however when I move the camera I get an exception
07-23 16:28:42.725: E/AndroidRuntime(19095): java.lang.RuntimeException: Unable to resume activity {ecm2.android/ecm2.android.EMGNoteMapActivity}: java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.os.Looper.loop(Looper.java:137)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-23 16:28:42.725: E/AndroidRuntime(19095): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 16:28:42.725: E/AndroidRuntime(19095): at java.lang.reflect.Method.invoke(Method.java:511)
07-23 16:28:42.725: E/AndroidRuntime(19095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-23 16:28:42.725: E/AndroidRuntime(19095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-23 16:28:42.725: E/AndroidRuntime(19095): at dalvik.system.NativeStart.main(Native Method)
07-23 16:28:42.725: E/AndroidRuntime(19095): Caused by: java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.
07-23 16:28:42.725: E/AndroidRuntime(19095): at maps.as.i.b(Unknown Source)
07-23 16:28:42.725: E/AndroidRuntime(19095): at maps.ah.w.a(Unknown Source)
07-23 16:28:42.725: E/AndroidRuntime(19095): at maps.ah.s.a(Unknown Source)
07-23 16:28:42.725: E/AndroidRuntime(19095): at maps.ah.an.b(Unknown Source)
07-23 16:28:42.725: E/AndroidRuntime(19095): at bgc.onTransact(SourceFile:92)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.os.Binder.transact(Binder.java:310)
07-23 16:28:42.725: E/AndroidRuntime(19095): at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.animateCamera(Unknown Source)
07-23 16:28:42.725: E/AndroidRuntime(19095): at com.google.android.gms.maps.GoogleMap.animateCamera(Unknown Source)
07-23 16:28:42.725: E/AndroidRuntime(19095): at ecm2.android.Fragments.EMGMap.centerOnNote(EMGMap.java:340)
07-23 16:28:42.725: E/AndroidRuntime(19095): at ecm2.android.Fragments.EMGMap.fetchMapSettings(EMGMap.java:283)
07-23 16:28:42.725: E/AndroidRuntime(19095): at ecm2.android.Fragments.EMGMap.onResume(EMGMap.java:289)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:917)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1820)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:412)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.Activity.performResume(Activity.java:5195)
07-23 16:28:42.725: E/AndroidRuntime(19095): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
07-23 16:28:42.725: E/AndroidRuntime(19095): ... 12 more
This is my camera movement on my 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 I take out the camera movement it does not crash but does not go back to the point of they moved away from it or something.
I check to make sure the map
is not null so I do not know what is causing the error?
Caused by: java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.
This should be clear enough. You cannot call
map.animateCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southWest,northEast),10));
before the layout is complete. You need to use 3 param version instead.
See the documentation here: newLatLngBounds
Aternatively you may listen for the layout to complete instead of calling this code in onResume
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With