[android] NullPointerException in MapView.onTouchEvent
I've seen this crash twice now (in crashlytics), but I don't have steps to reproduce it because it is happening on a customer's device:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.views.NativeMapView.setGestureInProgress(boolean)' on a null object reference
at com.mapbox.mapboxsdk.views.MapView.onTouchEvent(MapView.java:2845)
at android.view.View.dispatchTouchEvent(View.java:8471)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2373)
I took a look at the onTouchEvent code, and I think it would make sense to have a mNativeMapView != null check before calling setGestureInProgress
@JordanHamel thank you for reaching out and reporting this crash. These types of crashes are very useful to have! even though there (almost) not reproducible it still gives us a lot of information to work with.
I can raise a separate issue but my hunch is there is a underlying race condition. I don't believe the map is ready when 'onMapReady' is called.
For instance:
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapViewImpl = mapboxMap;
// Restore saved state
if (savedInstanceState != null) {
mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
mapboxMap.addMarkers(mMarkerList);
}
}
});
produces
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.mapbox.mapboxsdk.maps.NativeMapView.isPaused()' on a null object reference
at com.mapbox.mapboxsdk.maps.MapView.getTopOffsetPixelsForIcon(MapView.java:997)
at com.mapbox.mapboxsdk.maps.MapView.ensureIconLoaded(MapView.java:931)
at com.mapbox.mapboxsdk.maps.MapView.updateMarker(MapView.java:908)
at com.mapbox.mapboxsdk.maps.MapboxMap.updateMarker(MapboxMap.java:571)
at com.mapbox.mapboxsdk.annotations.Marker.setPosition(Marker.java:80)
at com.mapbox.mapboxsdk.annotations.MarkerOptions.getMarker(MarkerOptions.java:88)
at com.mapbox.mapboxsdk.maps.MapboxMap.prepareMarker(MapboxMap.java:969)
at com.mapbox.mapboxsdk.maps.MapboxMap.addMarkers(MapboxMap.java:539)
...
@snodnipper thanks for reaching out and reporting your crash! For future references, don't hesitate to create a new issue for your problem since it was not related to the onTouch one. I have looked into the crash and I'm fixing this and many others similar problems in #4211
#4211 was merged, closing
Hi Tobrun,
I am using below map box version in my application,
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:4.1.0-beta.3@aar'){
transitive = true
}
still getting the crash when network is changed.
Could you please help me out.
FATAL EXCEPTION: main Process: com.cisco.parking, PID: 14775 java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in com.mapbox.mapboxsdk.maps.MapView$ConnectivityReceiver@ead880f at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:880) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5312) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.NativeMapView.setReachability(boolean)' on a null object reference at com.mapbox.mapboxsdk.maps.MapView.onConnectivityChanged(MapView.java:2362) at com.mapbox.mapboxsdk.maps.MapView.access$3100(MapView.java:115) at com.mapbox.mapboxsdk.maps.MapView$ConnectivityReceiver.onReceive(MapView.java:2347) at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:870) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5312) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696) 06-28 15:18:02.280 14775-16111/com.cisco.parking D/Retrofit: ---- E
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.0-beta.1@aar'){ transitive=true } compile ('com.mapbox.mapboxsdk:mapbox-android-services:1.2.1@aar'){ transitive=true }
still app crash and the error is java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.NativeMapView.createSurface(android.view.Surface)' on a null object reference at com.mapbox.mapboxsdk.maps.MapView$SurfaceCallback.surfaceCreated(MapView.java:1410)
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.1@aar') { transitive = true } compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.2@aar') { transitive=true } compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.3@aar'){ transitive=true } ////i got this error no of times when app is in background for long time(App crash)
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.NativeMapView.createSurface(android.view.Surface)' on a null object reference at com.mapbox.mapboxsdk.maps.MapView$SurfaceCallback.surfaceCreated(MapView.java:426) java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.NativeMapView.createSurface(android.view.Surface)' on a null object reference at com.mapbox.mapboxsdk.maps.MapView$SurfaceCallback.surfaceCreated(MapView.java:426) at android.view.SurfaceView.updateWindow(SurfaceView.java:656) at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:266) at android.view.View.dispatchWindowVisibilityChanged(View.java:11139) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1290) at android.vie