AndroidStudio error implementing GoogleMaps

1

Good morning and thanks in advance, I am implementing google maps in an application and the following petardazo appears: InflateException: Binary XML file line # 6: Binary XML file line # 6: Error inflating class fragment, I took a whole day giving it turns and I do not give with the solution.

12-19 11:15:42.702 10823-10823/start2develop.mplaces E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: start2develop.mplaces, PID: 10823
                                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{start2develop.mplaces/start2develop.mplaces.Mapa}: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class fragment
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504)
                                                                       at android.app.ActivityThread.access$900(ActivityThread.java:165)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:150)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5546)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
                                                                    Caused by: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class fragment
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:558)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:434)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                       at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:420)
                                                                       at android.app.Activity.setContentView(Activity.java:2219)
                                                                       at start2develop.mplaces.Mapa.onCreate(Mapa.java:35)
                                                                       at android.app.Activity.performCreate(Activity.java:6367)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2397)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504) 
                                                                       at android.app.ActivityThread.access$900(ActivityThread.java:165) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                       at android.os.Looper.loop(Looper.java:150) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5546) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) 
                                                                    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:723)
                                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
                                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:817)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:434) 
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
                                                                       at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:420) 
                                                                       at android.app.Activity.setContentView(Activity.java:2219) 
                                                                       at start2develop.mplaces.Mapa.onCreate(Mapa.java:35) 
                                                                       at android.app.Activity.performCreate(Activity.java:6367) 
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110) 
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2397) 
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504) 
                                                                       at android.app.ActivityThread.access$900(ActivityThread.java:165) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                       at android.os.Looper.loop(Looper.java:150) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5546) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) 
                                                                    Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
                                                                       at com.google.maps.api.android.lib6.drd.q.b(:com.google.android.gms.DynamiteModulesB@11951446:40)
                                                                       at com.google.maps.api.android.lib6.auth.e.a(:com.google.android.gms.DynamiteModulesB@11951446:11)
                                                                       at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.DynamiteModulesB@11951446:112)
                                                                       at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms.DynamiteModulesB@11951446:25)
                                                                       at com.google.android.gms.maps.internal.h.onTransact(:com.google.android.gms.DynamiteModulesB@11951446:32)
                                                                       at android.os.Binder.transact(Binder.java:387)
                                                                       at bvd.a(:com.google.android.gms@11951446:2)
                                                                       at xdi.newMapFragmentDelegate(:com.google.android.gms@11951446:1)
                                                                       at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms@11951446:2)
                                                                       at xdh.onTransact(:com.google.android.gms@11951446:12)
                                                                       at android.os.Binder.transact(Binder.java:387)
                                                                       at com.google.android.gms.internal.zzed.zza(Unknown Source)
                                                                       at com.google.android.gms.maps.internal.zzf.zzH(Unknown Source)
                                                                       at com.google.android.gms.maps.SupportMapFragment$zzb.zzwg(Unknown Source)
                                                                       at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
                                                                       at com.google.android.gms.dynamic.zza.zza(Unknown Source)
                                                                       at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
                                                                       at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
                                                                       at android.support.v4.app.Fragment.onInflate(Fragment.java:1225)
                                                                       at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3511)
                                                                       at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
                                                                    at android.support.v4.app.FragmentActi

My code is as follows: Mapa.java activity

    package start2develop.mplaces;

 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable; 
 import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;
 import android.support.v4.content.ContextCompat;
 import com.google.android.gms.maps.CameraUpdateFactory;
 import com.google.android.gms.maps.GoogleMap;
 import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
 import com.google.android.gms.maps.OnMapReadyCallback;
 import com.google.android.gms.maps.SupportMapFragment;
 import com.google.android.gms.maps.model.BitmapDescriptorFactory;
 import com.google.android.gms.maps.model.LatLng;
 import com.google.android.gms.maps.model.Marker;
 import com.google.android.gms.maps.model.MarkerOptions;


 public class Mapa extends FragmentActivity
    implements OnMapReadyCallback, OnInfoWindowClickListener {
 private GoogleMap mapa;

@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);
    SupportMapFragment mapFragment = (SupportMapFragment)
            getSupportFragmentManager().findFragmentById(R.id.mapa);
    mapFragment.getMapAsync(this);
}

@Override public void onMapReady(GoogleMap googleMap) {
    mapa = googleMap;
    mapa.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION) ==
            PackageManager.PERMISSION_GRANTED) {
        mapa.setMyLocationEnabled(true);
        mapa.getUiSettings().setZoomControlsEnabled(true);
        mapa.getUiSettings().setCompassEnabled(true);
    }
    if (Lugares.size() > 0) {
        GeoPunto p = Lugares.elemento(0).getPosicion();
        mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(p.getLatitud(), p.getLongitud()), 12));
    }
    for (int n=0; n<Lugares.size(); n++) {
        Lugar lugar = Lugares.elemento(n);
        GeoPunto p = lugar.getPosicion();
        if (p != null && p.getLatitud() != 0) {
            BitmapDrawable iconoDrawable = (BitmapDrawable) getResources()
                    .getDrawable(lugar.getTipo().getRecurso());
            Bitmap iGrande = iconoDrawable.getBitmap();
            Bitmap icono = Bitmap.createScaledBitmap(iGrande,
                    iGrande.getWidth() / 7, iGrande.getHeight() / 7, false);
            mapa.addMarker(new MarkerOptions()
                    .position(new LatLng(p.getLatitud(), p.getLongitud()))
                    .title(lugar.getNombre()).snippet(lugar.getDireccion())
                    .icon(BitmapDescriptorFactory.fromBitmap(icono)));
        }
    }
    mapa.setOnInfoWindowClickListener(this);
}

@Override public void onInfoWindowClick(Marker marker) {
    for (int id=0; id<Lugares.size(); id++){
        if (Lugares.elemento(id). getNombre()
                .equals(marker.getTitle())){
            Intent intent = new Intent(this, VistaLugar.class);
            intent.putExtra("id", (long)id);
            startActivity(intent);
            break;
        } }}}

Mapa.xml =========================================================== ================

<?xml version="1.0" encoding="utf-8"?>




<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:id="@+id/mapa"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

  </RelativeLayout>

AndroidManifest.xml ================================================================================================== ========

<?xml version="1.0" encoding="utf-8"?>

                             

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version"/>
<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />
<permission
    android:name="start2develop.mplaces.permission.MAP_RECEIVE"
    android:protectionLevel="signature"/>



<application

    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name="start2develop.mplaces.Principal">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Acercade"
        android:label="Acerca de..."
        android:theme="@android:style/Theme.Dialog"/>
    <activity android:name=".VistaLugar"
        android:label="MisLugares..."/>
    <activity android:name=".EdicionLugar"
        android:label="Editar lugar"/>
    <activity android:name=".Mapa"
    android:screenOrientation="portrait"/>
</application>
</manifest>

values /google_maps_api.xml =======================

<?xml version="1.0" encoding="utf-8"?>
  <resources>
    <string name="google_maps_key" templateMergeStrategy="preserve"
     translatable="false">
        AIzaSyBipkse1lv3Ok6KjLxLSi83AppkAU89oMs</string>
 </resources>
    
asked by Raul.Rt 19.12.2017 в 11:31
source

3 answers

2

The problem is because you can not inflate a layout, which is actually mapa.xml , but in reality this layout can not be inflated due to this problem:

  

Caused by: java.lang.RuntimeException: API key not found. Check that    is in the element of   AndroidManifest.xml

When trying to load SupportMapFragment , it can not be configured correctly:

<fragment android:id="@+id/mapa"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

You must define your KEY API within the <application> tag of your AndroidManifest.xml , in fact this is the problem that is defined in the LogCat , since you are doing it outside of <application> :

 <application
        ...
        ...
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

 </application>

It is important to enable this KEY API, so that the map is displayed, ensures that this is done, go to link

Maps Android Studio is not shown

Do not forget the permission and definition of the feature:

    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    
answered by 19.12.2017 / 17:09
source
1

I had the same error, I tried placing:

<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

in my manifest and it worked, I hope it serves you

    
answered by 19.12.2017 в 17:12
-1

According to the code that you have pasted, I think you need to close in the xml file with

</string>
</resources>

Anyway to use the google KEY it should go in the google_maps_api.xml file and this file should have only:

<resources>
<string name="google_maps_key" templateMergeStrategy="preserve"
    translatable="false">
  AIzaSyBipkse1lv3Ok6KjLxLSi83AppkAU89oMs</string>
</resources>

And the file strings.xml , should have only the strings to be used by the app:

<resources>
    <string nstrings.xmlame="app_name">MPlaces</string>
    <string name="title_activity_maps">otro texto para mis Mapas</string>
     .....
</resources>
    
answered by 19.12.2017 в 11:46