Android Mapbox Inflating Error. Didn't Find Class Mapview
Solution 1:
I also faced this problem but when add this library to my dependencies
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.23.0'
Give this exeptions
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Even if i do not use navigation!! Then i realize i must initialize Mapbox before setContentView
So just move up like this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//first initialize Mapbox
Mapbox.getInstance(this, YOUR_MAPBOX_KEY);
//then setContentView(R.layout.activity_main);
}
And my problem solved
Solution 2:
Your XML for the MapView needs to be com.mapbox.mapboxsdk.maps.MapView
not com.mapbox.mapboxsdk.views.MapView
Other things that might help when using the latest Mapbox Android SDK version which is:
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:8.4.0@aar'){
transitive=true
}
make sure to include all the required permissions as well as Telemetry service:
<serviceandroid:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />
To control the MapView in 8.4.0 there is a new method called getMapAsync
which listens for when the map is ready. Once it is, you can add markers, change the camera position, etc.
This is how to ask for the permission:
Mapbox.getInstance(this, ACCESS_TOKEN);
Your onCreate
method should look something like this:
StringACCESS_TOKEN="ACCESS_TOKEN_HERE"@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Be sure to call this setContentView
Mapbox.getInstance(this, ACCESS_TOKEN);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(newOnMapReadyCallback() {
@OverridepublicvoidonMapReady(MapboxMap mapboxMap) {
// add markers, change camera position, etc. here!
}
...
Lastly, make sure you include all the mapView methods within your activities lifecycle. It will look like this:
// Activity lifecycle methods@OverrideprotectedvoidonStart() {
super.onStart();
mapView.onStart();
}
@OverridepublicvoidonResume() {
super.onResume();
mapView.onResume();
}
@OverridepublicvoidonPause() {
super.onPause();
mapView.onPause();
}
@OverrideprotectedvoidonStop() {
super.onStop();
mapView.onStop();
}
@OverrideprotectedvoidonDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@OverridepublicvoidonLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@OverrideprotectedvoidonSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
Post a Comment for "Android Mapbox Inflating Error. Didn't Find Class Mapview"