當我在XML文件中膨脹MapView時出現錯誤。 訪問令牌應該是正確的,我還將遠程信息處理包括在清單中。我使用這些版本mapbox 'com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]'
當在佈局文件中膨脹MapView時出錯
這裏是我的佈局檔。
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapviewmapbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:access_token="@string/accessToken"
mapbox:center_latitude="40.73581"
mapbox:center_longitude="-73.99155"
mapbox:style_url="mapbox://styles/mapbox/streets-v9"
mapbox:zoom="11" />
</RelativeLayout>`
和Java-文件:
package de.example.navdrawemap_2.maptest.Maps;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import de.example.navdrawemap_2.maptest.R;
public class MapMapboxActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_mapbox);
mapView = (MapView) findViewById(R.id.mapviewmapbox);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
}});
}
/*
TextView textViewTitle = (TextView)findViewById(R.id.texttitel);
TextView textViewTitleBig = (TextView)findViewById(R.id.texttitel_big);
TextView textViewSnippet = (TextView)findViewById(R.id.textsnippet);
Intent intentbundleStrings = getIntent();
if (intentbundleStrings != null) {
textViewTitleBig.setText(intentbundleStrings.getStringExtra("title"));
// textViewTitle.setText(intentbundleStrings.getStringExtra("title"));
// Titel im Header nachtragen
textViewSnippet.setText(intentbundleStrings.getStringExtra("snippet"));
}else{
textViewTitle.setText(intentbundleStrings.getStringExtra("N.A."));
textViewSnippet.setText(intentbundleStrings.getStringExtra("N.A."));
} */
// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}`
的logcat中顯示以下內容:
06-21 15:46:06.753 13892-13892/de.example.navdrawemap_2.maptest E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.example.navdrawemap_2.maptest, PID: 13892
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.example.navdrawemap_2.maptest/de.example.navdrawemap_2.maptest.Maps.MapMapboxActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
我添加的軟件包名稱也改變了工具:?上下文「.Maps.MapMapboxActivity」但第二個沒有解決的問題是什麼意思與‘你類的名稱 - ’謝謝 – MTwain
@twain,我完全改變了我的答案,請接受,如果這是正確的。 – RobLabs
非常感謝!真的很酷......我是真正的新和SO和github,但現在我知道了巨大的優勢。 – MTwain