1

Hi I am trying MapBox for navigation and getting crash like this

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)

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'

This is where I get the crash

     @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) {
//                enableLocationComponent();
                if (style.isFullyLoaded()) {
                    navigationMap = new NavigationMapboxMap(mapView, mMapboxMap);
//
//                // For Location updates
//                initializeLocationEngine();
//
//                // For navigation logic / processing
//        initializeNavigation(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.

shine_joseph
  • 2,922
  • 4
  • 22
  • 44
  • Have you checked [`ComponentNavigationActivity#onMapReady`][1] 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. [1]: https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/ComponentNavigationActivity.java#L131-L147 – Guardiola31337 Jan 21 '19 at 16:56

2 Answers2

1

I was facing the same issue and tried all the solutions. I updated to latest mapbox sdk 8.4.0, and followed the ComponentNavigationActivity#onMapReady, but still no luck.

Then I found that we need to put:

<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item>

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

setTheme(R.style.customInstructionView);

This solved the issue. I hope it helps!

0

https://github.com/mapbox/mapbox-navigation-android/issues/1692 is moving to fix this by providing a default if a valid style is not found. In the meantime, you can add this snippet to your style.xml to fix:

<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item>

Dan Nesfeder
  • 298
  • 1
  • 6