mapbox-navigation-android icon indicating copy to clipboard operation
mapbox-navigation-android copied to clipboard

crash on 'boolean com.mapbox.mapboxsdk.maps.Style.isFullyLoaded()' on a null object reference

Open shinejosephDev opened this issue 7 years ago • 3 comments

2019-01-20 19:00:16.331 32005-32005/com.example.mapboxtest E/Mbgl-MapChangeReceiver: Exception in onDidFinishLoadingStyle android.content.res.Resources$NotFoundException: Resource ID #0xffffffff at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:225) at android.content.res.Resources.getDrawableForDensity(Resources.java:887) at android.content.res.Resources.getDrawable(Resources.java:827) at android.content.Context.getDrawable(Context.java:626) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:463) at com.mapbox.mapboxsdk.location.Utils.getDrawable(Utils.java:75) at com.mapbox.mapboxsdk.location.LayerBitmapProvider.generateBitmap(LayerBitmapProvider.java:26) at com.mapbox.mapboxsdk.location.LocationLayerController.styleForeground(LocationLayerController.java:303) at com.mapbox.mapboxsdk.location.LocationLayerController.applyStyle(LocationLayerController.java:109) at com.mapbox.mapboxsdk.location.LocationLayerController.initializeComponents(LocationLayerController.java:92) at com.mapbox.mapboxsdk.location.LocationLayerController.<init>(LocationLayerController.java:84) at com.mapbox.mapboxsdk.location.LocationComponent.initialize(LocationComponent.java:991) at com.mapbox.mapboxsdk.location.LocationComponent.activateLocationComponent(LocationComponent.java:292) at com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap.initializeLocationComponent(NavigationMapboxMap.java:549) at com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap.<init>(NavigationMapboxMap.java:80) at com.example.mapboxtest.MainActivity$1.onStyleLoaded(MainActivity.java:45) at com.mapbox.mapboxsdk.maps.MapboxMap.notifyStyleLoaded(MapboxMap.java:835) at com.mapbox.mapboxsdk.maps.MapboxMap.onFinishLoadingStyle(MapboxMap.java:202) at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1164) at com.mapbox.mapboxsdk.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:194) at com.mapbox.mapboxsdk.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:979) 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:6892) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)

I am getting a crash like this.

These are the dependencies that I am using now

// MAP BOX
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.0.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.27.0'
` @Override
    public void onMapReady(@NonNull MapboxMap mapboxMap) {
        mMapboxMap = mapboxMap;
        mapboxMap.setStyle(new Style.Builder().fromUrl(getString(R.string.navigation_guidance)), new Style.OnStyleLoaded() {
            @Override
            public void onStyleLoaded(@NonNull Style style) {
                if (style.isFullyLoaded()) {
                    navigationMap = new NavigationMapboxMap(mapView, mMapboxMap);
                    navigationMap.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_NONE);
                }
            }
        });
    }`

This line is causing the issue

navigationMap = new NavigationMapboxMap(mapView, mMapboxMap);

I checked this link https://github.com/mapbox/mapbox-gl-native/wiki/Android-6.x-to-7.x-migration-guide

and found something like this

In order to avoid java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.mapbox.mapboxsdk.maps.Style.isFullyLoaded()' on a null object reference, the provided style parameter in the LocationComponent#activate method has to be @NonNull and fully loaded. The best way is to pass the style provided in the OnStyleLoaded callback.

But still no luck. Can someone look into this.

shinejosephDev avatar Jan 20 '19 15:01 shinejosephDev

Hey @shinejosephDev 👋 thanks for reaching out and report your issue.

Have you 👀 ComponentNavigationActivity#onMapReady from the test app? It seems you're using a similar setup although it doesn't crash here 🤔

Could you add some more information for reproducing the crash or any other specifics around your setup? That would be really helpful because without having additional information, I'm unable to reproduce.

For implementation questions, you can send a message to [email protected] and reference this ticket. Also, please check out our help docs or post your question on Stack Overflow. The Android team is watching these questions. Thanks for understanding!

Closing here as OP was already asked in Stack Overflow https://stackoverflow.com/questions/54277903/android-crash-on-boolean-com-mapbox-mapboxsdk-maps-style-isfullyloaded-on-a

Guardiola31337 avatar Jan 21 '19 16:01 Guardiola31337

hi shine, i was facing the same issue and i tried all the solution. i updated to latest mapbox sdk 8.4.0, and is was following the ComponentNavigationActivity#onMapReady but still no luck than i found that we need to put

<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item> <item name="navigationViewRouteOverviewDrawable">@drawable/ic_route_preview</item>

inside the custom instructions view style and apply it inside onCreate() like this

// For styling the InstructionView setTheme(R.style.customInstructionView);

this solved the issue i hope it helps

here is the full style i used

<style name="customInstructionView" parent="AppTheme.ZIRO_NoActionBar"> <item name="navigationViewRouteStyle">@style/NavigationMapRoute</item> <item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item> <item name="navigationViewDestinationMarker">@drawable/map_marker_light</item> <item name="navigationViewRouteOverviewDrawable">@drawable/ic_route_preview</item> <item name="navigationViewMapStyle">@string/mapbox_style_dark</item> </style>

pawanparihar05 avatar Sep 30 '19 08:09 pawanparihar05

我也出现了这种bug,直接导致app奔溃闪退了。有人知道怎么解决吗?

KevinZzq886 avatar Jun 15 '22 06:06 KevinZzq886