android – Error while applying with Mapbox SDK


Alguien puede ayudarme o explicarme that sucede? Learn more about the error with access to the Mapbox token for not having to say:

MainActivity.java

com.demo.demor package;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.MenuItem;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;

import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

Public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

MapView Private MapView;

@Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);

Mapbox.getInstance (this, getString (R.string.access_token));

Toolbar Toolbar = findViewById (R.id.toolbar);
setSupportActionBar (toolbar);

FloatingActionButton fab = findViewById (R.id.fab);
fab.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View view) {
Snackbar.make (see, "Replace by your own action", Snackbar.LENGTH_LONG)
.setAction ("Action", null) .show ();
}
});

DrawerLayout drawer = findViewById (R.id.drawer_layout);
NavigationView navigationView = findViewById (R.id.nav_view);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener (toggle);
toggle.syncState ();
navigationView.setNavigationItemSelectedListener (this);

mapView = findViewById (R.id.mapView);
mapView.onCreate (savedInstanceState);
mapView.getMapAsync (new OnMapReadyCallback () {
@Override
public void onMapReady (@NoNull final MapboxMap mapboxMap) {

mapboxMap.setStyle (Style.LIGHT, new Style.OnStyleLoaded () {
@Override
public void onStyleLoaded (style @NonNull) {
// Add the marker image to the map
style.addImage ("marker-icon-id",
BitmapFactory.decodeResource (
MainActivity.this.getResources (), R.drawable.mapbox_marker_icon_default));

GeoJsonSource geoJsonSource = new GeoJsonSource ("source-id", Feature.fromGeometry (
Point.fromLngLat (-87,679, 41,885)));
style.addSource (geoJsonSource);

SymbolLayer symbolLayer = new SymbolLayer ("layer id", "source id");
symbolLayer.withProperties (
PropertyFactory.iconImage ("marker-icon-id")
)
style.addLayer (symbolLayer);

}
});
}
});
}

@Override
public void onBackPressed () {
DrawerLayout drawer = findViewById (R.id.drawer_layout);
if (drawer.isDrawerOpen (GravityCompat.START)) {
drawer.closeDrawer (GravityCompat.START);
} other {
super.onBackPressed ();
}
}

@Override
Public Boolean onCreateOptionsMenu (Menu Menu) {
// Inflate the menu; this adds elements to the action bar if it is present.
getMenuInflater () .flate (R.menu.menu_menu, menu);
return true;
}

@Override
Boolean public onOptionsItemSelected (MenuItem element) {
// Manage the elements of the action bar by clicking here The action bar will be
// automatically manage clicks on the Home / Up button, so long
// when you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId ();

// noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected (item);
}

@SuppressWarnings ("StatementWithEmptyBody")
@Override
Boolean public onNavigationItemSelected (MenuItem element) {
// Manage the navigation view items clicked here.
int id = item.getItemId ();

if (id == R.id.nav_home) {
// Manage the action of the camera
} else if (id == R.id.nav_gallery) {

} else if (id == R.id.nav_slideshow) {

} else if (id == R.id.nav_tools) {

} else if (id == R.id.nav_share) {

} else if (id == R.id.nav_send) {

}

DrawerLayout drawer = findViewById (R.id.drawer_layout);
drawer.closeDrawer (GravityCompat.START);
return true;
}

// Add own mapView life cycle methods to the activity lifecycle methods
@Override
public void onStart () {
super.onStart ();
mapView.onStart ();
}

@Override
public void onResume () {
super.onResume ();
mapView.onResume ();
}

@Override
public void onPause () {
super.onPause ();
mapView.onPause ();
}

@Override
public void onStop () {
super.onStop ();
mapView.onStop ();
}

@Override
public void onLowMemory () {
super.onLowMemory ();
mapView.onLowMemory ();
}

@Override
void protected onDestroy () {
super.onDestroy ();
mapView.onDestroy ();
}

@Override
void protected onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState;
mapView.onSaveInstanceState (outbound state);
}
}

content_main.xml




    


ERROR Run

E / AndroidRuntime: FATAL EXCEPTION: Main
Process: com.demo.demor, PID: 14149
java.lang.RuntimeException: unable to start activity ComponentInfo {com.demo.demor / com.demo.demor.MainActivity}: android.view.InflateException: Binary XML File Line 11: XML File Line binary 12: Error inflating class com.mapbox.mapboxsdk.maps.MapView
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11 (Unknown source: 0)
to android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1593)
to android.os.Handler.dispatchMessage (Handler.java:105)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6541)
to java.lang.reflect.Method.invoke (native method)
on com.android.internal.os.Zygote $ MethodAndArgsCaller.run (Zygote.java:240)
on com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)
Caused by: android.view.InflateException: binary XML file line # 11: binary XML file line # 12: error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: android.view.InflateException: binary XML file line # 12: error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: java.lang.reflect.InvocationTargetException
to java.lang.reflect.Constructor.newInstance0 (Native method)
on java.lang.reflect.Constructor.newInstance (Constructor.java:334)
at android.view.LayoutInflater.createView (LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:863)
on android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:824)
at android.view.LayoutInflater.parseInclude (LayoutInflater.java:995)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:859)
on android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:824)
at android.view.LayoutInflater.parseInclude (LayoutInflater.java:995)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:859)
on android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:824)
at android.view.LayoutInflater.inflate (LayoutInflater.java:515)
at android.view.LayoutInflater.inflate (LayoutInflater.java:423)
at android.view.LayoutInflater.inflate (LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:140)
at com.demo.demor.MainActivity.onCreate (MainActivity.java:39)
at android.app.Activity.performCreate (Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11 (Unknown source: 0)
to android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1593)
to android.os.Handler.dispatchMessage (Handler.java:105)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6541)
to java.lang.reflect.Method.invoke (native method)
on com.android.internal.os.Zygote $ MethodAndArgsCaller.run (Zygote.java:240)
on com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)
Caused by: com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException:
The use of MapView requires calling Mapbox.getInstance (context context, String accessToken) before inflating or creating the view. The token setting is required when using a Mapbox service.
Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
at the address com.mapbox.mapboxsdk.maps.MapView.initialize (MapView.java:122)
at the com.mapbox.mapboxsdk.maps.MapView address. (MapView.java:98)
… 31 more