Android 在空对象引用上 'boolean com.mapbox.mapboxsdk.maps.Style.isFullyLoaded()' 崩溃,
Android crash on 'boolean com.mapbox.mapboxsdk.maps.Style.isFullyLoaded()' on a null object reference,
您好,我正在尝试使用 MapBox 进行导航并遇到这样的崩溃
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.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)
这些是我现在使用的依赖项
// 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) {
// 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);
}
}
});
}
这一行导致了问题
navigationMap = new NavigationMapboxMap(mapView, mMapboxMap);
我检查了这个linkhttps://github.com/mapbox/mapbox-gl-native/wiki/Android-6.x-to-7.x-migration-guide
并找到了类似的东西
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.
但还是没有运气。
https://github.com/mapbox/mapbox-navigation-android/issues/1692 正在通过在未找到有效样式时提供默认值来解决此问题。同时,您可以将此代码段添加到您的 style.xml
以修复:
<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item>
我遇到了同样的问题并尝试了所有解决方案。我更新到最新的 mapbox sdk 8.4.0,并遵循了 ComponentNavigationActivity#onMapReady,但仍然没有运气。
然后我发现我们需要放:
<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item>
在自定义指令视图样式中并将其应用到 onCreate()
中,如下所示:
setTheme(R.style.customInstructionView);
这解决了问题。希望对您有所帮助!
您好,我正在尝试使用 MapBox 进行导航并遇到这样的崩溃
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.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)
这些是我现在使用的依赖项
// 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) {
// 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);
}
}
});
}
这一行导致了问题
navigationMap = new NavigationMapboxMap(mapView, mMapboxMap);
我检查了这个linkhttps://github.com/mapbox/mapbox-gl-native/wiki/Android-6.x-to-7.x-migration-guide
并找到了类似的东西
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.
但还是没有运气。
https://github.com/mapbox/mapbox-navigation-android/issues/1692 正在通过在未找到有效样式时提供默认值来解决此问题。同时,您可以将此代码段添加到您的 style.xml
以修复:
<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item>
我遇到了同样的问题并尝试了所有解决方案。我更新到最新的 mapbox sdk 8.4.0,并遵循了 ComponentNavigationActivity#onMapReady,但仍然没有运气。
然后我发现我们需要放:
<item name="navigationViewLocationLayerStyle">@style/NavigationLocationLayerStyle</item>
在自定义指令视图样式中并将其应用到 onCreate()
中,如下所示:
setTheme(R.style.customInstructionView);
这解决了问题。希望对您有所帮助!