Mapbox应用程序崩溃时启动
我想创建一个简单的mapbox应用程序,它显示一个mapview。调试时没有显示特定错误,但应用程序在启动时崩溃。这里是我创建的.java文件。Mapbox应用程序崩溃时启动
public class MainActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,String.valueOf(R.string.access_token));
setContentView(R.layout.activity_main);
mapView=(MapView)findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
}
});
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
}
这里是我的.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
tools:context="com.example.logusubramaniyan.choropleth1.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTilt="20"
mapbox:mapbox_cameraZoom="12"/>
</LinearLayout>
我不明白为什么活动失败当对模拟器或任何device.Any想法运行启动?
这是我的StackTrace结果。
致命异常:主 工艺:com.example.logusubramaniyan.choropleth1,PID:17191 了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.logusubramaniyan.choropleth1/com.example.logusubramaniyan.choropleth1 .MainActivity}:android.view.InflateException:二进制XML文件行#16:二进制XML文件行#16:错误在android.app.ActivityThread.performLaunchActivity
String.valueOf()
不能正常将其转换为一个字符串值,因此无法正确读取访问令牌。
尝试直接粘贴访问令牌而不是提供它是R.string.something。
您的问题应该解决。
尝试充气类com.mapbox.mapboxsdk.maps.MapView 把这条线
Mapbox.getInstance(this,String.valueOf(R.string.access_token));
setContentView行后检查。
我检查过,它仍然崩溃,甚至没有启动。 –
尝试增加访问令牌来查看布局这样的: mapbox:access_token="access_token"
它没有识别出布局文件中的任何内容。 –
对不起,还要添加'xmlns:mapbox =“http://schemas.android.com/apk/res-auto”' – cab404
我也已经添加了。仍然在运行时,它显示错误。这是错误 - :找不到包'com.example.logusubramaniyan.choropleth1'中属性'access_token'的资源标识符 –
向我们展示您的堆栈跟踪崩溃。 – SripadRaj
后logcat请。 –
阅读https://www.mapbox.com/help/first-steps-android-sdk/ –