我正在尝试使用新的mapbox为安卓v10,特别是新的三维地形功能。所有的例子都是在Kotlin,我已经遵循了下面的在线指南,但我始终遇到相同的错误信息。
在线示例:
mapboxMap.loadStyle(
styleExtension = style(Style.SATELLITE_STREETS) {
+rasterDemSource("TERRAIN_SOURCE") {
url("mapbox://mapbox.mapbox-terrain-dem-v1")
}
+terrain("TERRAIN_SOURCE") {
exaggeration(1.1)
}
)下面是我使用的代码:
public class MainActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
//mapView.getMapboxMap().loadStyleUri(Style.OUTDOORS);
MapboxMap mapboxMap = mapView.getMapboxMap();
StyleContract.StyleExtension styleExtension = new StyleContract.StyleExtension() {
@NonNull
@Override
public String getStyleUri() {
return Style.SATELLITE;
}
@NonNull
@Override
public List<StyleContract.StyleSourceExtension> getSources() {
RasterDemSource rasterDemSource = new RasterDemSource(new RasterDemSource.Builder("TERRAIN_SOURCE"));
rasterDemSource.url("mapbox://mapbox.mapbox-terrain-v2");
List<StyleContract.StyleSourceExtension> ex = new ArrayList<StyleContract.StyleSourceExtension>();
ex.add(rasterDemSource);
return ex;
}
@NonNull
@Override
public List<StyleContract.StyleImageExtension> getImages() {
return null;
}
@NonNull
@Override
public List<Pair<StyleContract.StyleLayerExtension, LayerPosition>> getLayers() {
return null;
}
@Nullable
@Override
public StyleContract.StyleLightExtension getLight() {
return null;
}
@Nullable
@Override
public StyleContract.StyleTerrainExtension getTerrain() {
Terrain terrain = new Terrain("TERRAIN_SOURCE");
terrain.exaggeration(1.1);
return null;
}
};
mapboxMap.loadStyle(styleExtension);
}
}我一直得到以下错误代码:
com.mapbox.maps.MapboxMap.onFinishLoadingStyleExtension$sdk_release(MapboxMap.kt:1349) 2021-11-02 17:21:39.439 23646-23646/com.example.myapplication W/System.err: java.lang.NullPointerException:尝试调用空对象引用上的接口方法'java.util.Iterator java.lang.Iterable.iterator()‘2021-11-02-17:21:39.439-23646/com.example.myapplication W/System.err: at 2021-11-02 17:21:39com.mapbox.maps.MapboxMap$loadStyle$1.onStyleLoaded(MapboxMap.kt:163) 23646-23646/com.example.myapplication W/System.err: at com.mapbox.maps.MapboxMap$initializeStyleLoad$1.onStyleLoaded(MapboxMap.kt:214) 2021-11-02 17:21:39.439 23646-23646/com.example.myapplication W/System.err: at com.mapbox.maps.MapboxMap$initializeStyleLoad$1.onStyleLoaded(MapboxMap.kt:214) 2021-11-02 17:21:39.439 23646-23646/com.example.myapplication W/System.err: at com.mapbox.maps.StyleObserver。com.mapbox.maps.NativeObserver.notify(NativeObserver.kt:61) 2021-11-02 17:21:39.439 23646-23646/com.example.myapplication W/System.err: at onStyleLoaded 2021-11-02 17:21:39.439 -23646/com.example.myapplication W/System.err:
在android.os.MessageQueue.nativePollOnce(本地方法) 2021-11-02 17:21:39.439 23646-23646/com.example.myapplication W/System.err:
android.os.MessageQueue.next(MessageQueue.java:335) 2021-11-02 17:21:39.440 23646-23646/com.example.myapplication W/System.err:
地址: android.app.ActivityThread.main(ActivityThread.java:8633) 2021-11-02 17:21:39.440 23646-23646/com.example.myapplication W/System.err: at android.os.Looper.loop 2021-11-02 17:21:39.440 -23646/com.example.myapplication W/System.err:
在java.lang.reflect.Method.invoke(本地方法) 2021-11-02 17:21:39.440 23646-23646/com.example.myapplication W/System.err:
在com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) 2021-11-02 17:21:39.440 23646-23646/com.example.myapplication W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 2021-11-02 17:21:39.446 23646-23646/com.example.myapplication E/libc++abi:终止jni::PendingJavaException 2021-11-02 17:21:39.447 23646-23646/com。example.myapplication A/libc:致命信号6代码-1 (SI_QUEUE)在tid 23646 (e.myapplication),pid 23646 (e.myapplication)中
发布于 2021-11-07 23:10:39
原来我使用的样式扩展不正确,下面的内容现在起作用了:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
MapboxMap mapboxMap = mapView.getMapboxMap();
mapboxMap.loadStyle(createStyle());
}
private StyleContract.StyleExtension createStyle() {
StyleExtensionImpl.Builder builder = new StyleExtensionImpl.Builder(Style.SATELLITE);
RasterDemSource rasterDemSource = new RasterDemSource(new RasterDemSource.Builder("TERRAIN_SOURCE").tileSize(514));
rasterDemSource.url("mapbox://mapbox.mapbox-terrain-dem-v1");
builder.addSource(rasterDemSource);
Terrain terrain = new Terrain("TERRAIN_SOURCE");
terrain.exaggeration(1.1);
builder.setTerrain(terrain);
return builder.build();
}发布于 2021-11-07 04:25:09
mapboxMap.loadStyle(
styleExtension = style(Style.SATELLITE_STREETS) {
+rasterDemSource("TERRAIN_SOURCE") {
url("mapbox://mapbox.mapbox-terrain-dem-v1")
}
+terrain("TERRAIN_SOURCE") {
exaggeration(1.1)
}
)而不是这个,尝试使用
mapboxMap.loadStyle(
styleExtension = style(Style.SATELLITE) {
+rasterDemSource("TERRAIN_SOURCE") {
url("mapbox://mapbox.mapbox-terrain-dem-v1")
}
+terrain("TERRAIN_SOURCE") {
exaggeration(1.1)
}
)希望它对我有帮助,因为它对我来说是完美的,没有任何问题。
https://stackoverflow.com/questions/69805425
复制相似问题