You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
I integrated MapBox 4.0.1 in my mobile app, It's an navigation application like Waze for example.
I've a problem in a particular case : the user click on the back button (onBackPressed was called) when MapBox drawing a Markers on a Map.
The NullPointer Exception is generated here : mapboxMap.addMarker(op);
but looking closer the StrackTrace, we notice (MapView.java:988)
return mNativeMapView.addMarker(marker);
I Think that when the user "onBackPressed" the object "mNativeMapView" becomes "null"
here is the code in question :
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
[..]
if (mapboxMap != null) {
MarkerOptions op = new MarkerOptions().position(...).title(...).icon(...);
mapboxMap.addMarker(op);
}
[..]
}
}
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'long com.mapbox.mapboxsdk.maps.NativeMapView.addMarker(com.mapbox.mapboxsdk.annotations.Marker)' on a null object reference
at com.mapbox.mapboxsdk.maps.MapView.addMarker(MapView.java:988)
at com.mapbox.mapboxsdk.maps.MapboxMap.addMarker(MapboxMap.java:591)
at com.mapbox.mapboxsdk.maps.MapboxMap.addMarker(MapboxMap.java:574)
at fr.agemos.labbe.android.controller.MapBoxActivity$5.onMapReady(MapBoxActivity.java:1370)
at com.mapbox.mapboxsdk.maps.MapView.getMapAsync(MapView.java:2442)
at fr.agemos.labbe.android.controller.MapBoxActivity.drawBridges(MapBoxActivity.java:1327)
at fr.agemos.labbe.android.controller.MapBoxActivity.resultOverPassAsyncTask(MapBoxActivity.java:1913)
at fr.agemos.labbe.android.service.asynctask.AsyncTaskOverPass.onPostExecute(AsyncTaskOverPass.java:161)
at fr.agemos.labbe.android.service.asynctask.AsyncTaskOverPass.onPostExecute(AsyncTaskOverPass.java:29)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6066)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
@bleege suggesting to put this on the 4.1.0 milestone. This solves the edge case of crashing if a marker is being added when the hosting Activity is being destroyed. Code can be viewed in 964a6cd and PR created in #5150.
@tobrun Actually with the time difference and it being Memorial Day weekend I'll just merge this fix into master now and then cherry pick it over to the release branch. This will make this fix available sooner for everyone. I'll take care of this now.
Cherry picked to release-android-v4.1.0. I'm going to start a new SNAPSHOT build so this (along with the other changes from today) will be available within an hour or so.
Activity
tobrun commentedon May 25, 2016
@NonowPoney
Thank you for reaching out and reporting your issue.
The underlying code for
addMarkeris:It's not incorporating the check to validate if the underlying
mNativeMapViewhas been destroyed:For example:
[android] #5106 - add check for destroyed map view for addMarker()
tobrun commentedon May 26, 2016
@bleege suggesting to put this on the
4.1.0milestone. This solves the edge case of crashing if a marker is being added when the hosting Activity is being destroyed. Code can be viewed in 964a6cd and PR created in #5150.Schumi09 commentedon May 27, 2016
The same exception is thrown if you add a marker while the screen orientation changes.
bleege commentedon May 27, 2016
@tobrun Sounds good to me. Let's redo the PR to get it onto the 4.1.0 Release Branch instead of master though.
bleege commentedon May 27, 2016
@tobrun Actually with the time difference and it being Memorial Day weekend I'll just merge this fix into
masternow and then cherry pick it over to the release branch. This will make this fix available sooner for everyone. I'll take care of this now.[android] #5106 - add check for destroyed map view for addMarker()
bleege commentedon May 27, 2016
Rebased and Merged to
master[android] #5106 - add check for destroyed map view for addMarker()
bleege commentedon May 27, 2016
Cherry picked to
release-android-v4.1.0. I'm going to start a new SNAPSHOT build so this (along with the other changes from today) will be available within an hour or so.BrunoDrean commentedon May 27, 2016
Thank you for your help !