2017-09-14 234 views
-2

我想創建一個簡單的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

+0

向我們展示您的堆棧跟蹤崩潰。 – SripadRaj

+0

後logcat請。 –

+0

閱讀https://www.mapbox.com/help/first-steps-android-sdk/ –

回答

-1

String.valueOf()不能正常將其轉換爲一個字符串值,因此無法正確讀取訪問令牌。

嘗試直接粘貼訪問令牌而不是提供它是R.string.something。

您的問題應該解決。

0

嘗試充氣類com.mapbox.mapboxsdk.maps.MapView 把這條線

Mapbox.getInstance(this,String.valueOf(R.string.access_token)); 

setContentView行後檢查。

+0

我檢查過,它仍然崩潰,甚至沒有啓動。 –

0

嘗試增加訪問令牌來查看佈局這樣的: mapbox:access_token="access_token"

+0

它沒有識別出佈局文件中的任何內容。 –

+0

對不起,還要添加'xmlns:mapbox =「http://schemas.android.com/apk/res-auto」' – cab404

+0

我也已經添加了。仍然在運行時,它顯示錯誤。這是錯誤 - :找不到包'com.example.logusubramaniyan.choropleth1'中屬性'access_token'的資源標識符 –