2016-06-21 5 views
2

Ich habe einen Fehler bekommen, wenn es darum geht, die MapView in der XML-Datei aufzublasen. Das Zugriffs-Token sollte korrekt sein und ich schließe auch die Telematik in das Manifest ein. Ich verwende diese Version der Mapbox 'com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]'Fehler beim Aufblasen der MapView in Layout-Datei

Hier ist meine Layout-Datei.

<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>` 

Und die Java-Datei:

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); 
} 

} `

The Logcat zeigt folgendes:

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 

Antwort

0

@twain, zum Glück hast du deinen Code in Github gepostet. Die Ursache des Problems waren die Berechtigungen.

Hier ist die Github commit that fixes this up.

Der Hinweis, den ich sah, war im Protokoll, die Schlüsselzeile der Quelle für Android-Berechtigungen ist hier.

Es ist sehr kryptisch, aber ich habe dieses Problem schon einmal kennengelernt, daher führte es mich zur Lösung.

Sie benötigten

android.permission.ACCESS_WIFI_STATE 

statt

android.permission.ACCESS_NETWORK_STATE 

I zurückgesetzt auch den MapBox Android SDK neueste Version, aber ich bin mir nicht sicher, was das hat Affekt. Hier

compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]'){ 
    transitive=true 
} 

ist das Beispiel der MapBox Karte von Ihrer App über Potsdam.

Mapbox Map

+0

Ich füge den Paketnamen hinzu und ändere auch den tools: context zu ".Maps.MapMapboxActivity". Aber der zweite löst das Problem nicht. Was meinst du mit "Und der Name deiner Klasse -"? Danke – MTwain

+0

@twain, ich habe meine Antwort total geändert Bitte akzeptieren Sie, wenn das korrekt ist – RobLabs

+0

Vielen Dank! Wirklich cool ... Ich bin echt neu in SO und GitHub, aber jetzt kenne ich die großen Vorteile. – MTwain

0

Ich denke, es Speicherproblem sein könnte. Ich hatte ähnliche Probleme beim Aufblasen komplexer Ansichten. Versuchen Sie, die Breite und Höhe der Karte zu reduzieren.

+0

Nicht wirklich. Ich reduziere das Map-Objekt, aber es funktioniert nicht und zeigt den gleichen Fehler. :( – MTwain

-1

Sie benötigen

Mapbox.getInstance(getApplicationContext(), "MY_DEFAULT_PUBLIC_API_KEY"); 

In der Anwendungsklasse hinzufügen stattdessen in Aktivität.

Verwandte Themen