Exception in onDidFinishLoadingStyle Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.location.LocationComponent.setLocationComponentEnabled(boolean)' on a null object reference
See original GitHub issueDescribe the bug
private vodid stateChanged() getting called before mLocationComponent
is initiated on map load hence resulting in NullPointerException
2020-05-11 13:04:23.746 9008-9008/? E/Mbgl-MapChangeReceiver: Exception in onDidFinishLoadingStyle
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.location.LocationComponent.setLocationComponentEnabled(boolean)' on a null object reference
at com.mapbox.rctmgl.components.location.LocationComponentManager.stateChanged(LocationComponentManager.java:80)
at com.mapbox.rctmgl.components.location.LocationComponentManager.showUserLocation(LocationComponentManager.java:55)
at com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocation.onStyleLoaded(RCTMGLNativeUserLocation.java:55)
at com.mapbox.mapboxsdk.maps.MapboxMap.getStyle(MapboxMap.java:119)
at com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocation.onMapReady(RCTMGLNativeUserLocation.java:43)
at com.mapbox.mapboxsdk.maps.MapView.getMapAsync(MapView.java:1109)
at com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocation.addToMap(RCTMGLNativeUserLocation.java:30)
at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.addQueuedFeatures(RCTMGLMapView.java:526)
at com.mapbox.rctmgl.components.mapview.RCTMGLMapView$1.onStyleLoaded(RCTMGLMapView.java:430)
at com.mapbox.mapboxsdk.maps.MapboxMap.notifyStyleLoaded(MapboxMap.java:964)
at com.mapbox.mapboxsdk.maps.MapboxMap.onFinishLoadingStyle(MapboxMap.java:221)
at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1316)
at com.mapbox.mapboxsdk.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
at com.mapbox.mapboxsdk.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1106)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:160)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
2020-05-11 13:04:23.751 9008-9312/? E/ReactNativeJS: 'Mapbox error', 'Exception in onDidFinishLoadingStyle', { level: 'error',
tag: 'Mbgl-MapChangeReceiver',
message: 'Exception in onDidFinishLoadingStyle' }
To Reproduce
Example:
<MapboxGL.MapView
ref={map}
style={[styles.container, props.style]}
compassEnabled={false}
onRegionIsChanging={onRegionIsChanging}
rotateEnabled={props.rotationEnabled && !props.disableInteractions}
onRegionDidChange={onRegionChanged}
regionDidChangeDebounceTime={10}
pitchEnabled={false}
scrollEnabled={!props.disableInteractions}
zoomEnabled={!props.disableInteractions}
onLayout={props.onLayout}
onPress={onPress}
>
<MapboxGL.Camera
ref={camera}
maxZoomLevel={18}
defaultSettings={mapSettings}
followUserLocation={props.keepUserCentered}
followUserMode="normal"
/>
{props.children}
{/*
//@ts-ignore*/}
{props.showUserLocation && <MapboxGL.UserLocation showsUserHeadingIndicator renderMode="native" />}
</MapboxGL.MapView>
Versions:
- Platform: Android
- Emulator/ Simulator: no
- OS: Android 8
- react-native-mapbox-gl 8.1.0-beta
- React Native Version 61.2
Additional context seems to be fixed by simple early return:
private void stateChanged() {
if (mLocationComponent == null) return;
...
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (9 by maintainers)
Top Results From Across the Web
Exception in onDidFinishLoadingStyle Attempt to ... - GitHub
setLocationComponentEnabled (boolean)' on a null object reference #869 ... Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.location.
Read more >Developers - Exception in onDidFinishLoadingStyle Attempt to ...
setLocationComponentEnabled (boolean)' on a null object reference. ... Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.location.
Read more >Android crash on 'boolean com.mapbox ... - Stack Overflow
NullPointerException: Attempt to invoke virtual method 'boolean com.mapbox.mapboxsdk.maps.Style.isFullyLoaded()' on a null object reference, the ...
Read more >LocationComponent - Mapbox docs
The Location Component provides location awareness to your mobile application. Enabling this component provides a contextual experience to your users by ...
Read more >com.mapbox.mapboxsdk.annotations.MarkerOptions
@Override public void onMapLongClick(@NonNull LatLng point) { if (originMarker == null) { originMarker = mapboxMap.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also agree to reopen. I have this issue with version 8.1.0-rc10 .
I get this issue when I have
renderMode="native"
on the<MapboxGL.UserLocation />
when the<Camera />
does not havefollowUserLocation
prop (iffollowUserLocation
is set to true it works)Any update on this? I can’t even use MapboxGL.MarkerView