gpt4 book ai didi

java - Android MapBlocks 中的空点异常错误

转载 作者:行者123 更新时间:2023-12-01 18:24:18 25 4
gpt4 key购买 nike

我正在尝试关注This tutorial 我收到一个错误这是堆栈跟踪

Process: com.example.mapp, PID: 7624
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapp/com.example.mapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.MapView.onCreate(android.os.Bundle)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.MapView.onCreate(android.os.Bundle)' on a null object reference
at com.example.mapp.MainActivity.onCreate(MainActivity.java:21)

这是activity_main.xml 的 map View 部分

    <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="37.7747"
mapbox:mapbox_cameraTargetLng="-122.4443"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10"
mapbox:mapbox_cameraZoom="12"
/>

这是完整的MainActivity.Java(删除了所有导入+ map 框的更多功能)

public class MainActivity extends AppCompatActivity {

private MapView mapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Mapbox.getInstance(this, getString(R.string.access_token) );
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
}

@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}

@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}

@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
}

我尝试了以下链接,但它们不起作用 link 1 link 2 link 4

提前致谢。

最佳答案

您正在关注的 YouTube 视频有点旧了。现在设置一个简单的 MapView 的方式有所不同。例如,您无法再通过 XML 设置 map 样式 URL。

https://docs.mapbox.com/android/maps/examples/create-a-simple-map-view显示设置 Mapbox map 的基本方法。

关于java - Android MapBlocks 中的空点异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60252790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com