Binary line of XML file #: error inflating a fragment of a class: only on Android (6.0) -Marshmallow

I can not show google map on Android M.

Here is the xml layout:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:wheel="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/toolbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"/> <LinearLayout android:orientation="vertical" android:id="@+id/content_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.google.android.gms.maps.SupportMapFragment" android:id="@+id/googleMap" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center" /> </LinearLayout> </LinearLayout> 

AndroidManifest File:

 <permission android:name="com.xxx.yyy.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.xxx.yyy.permission.MAPS_RECEIVE" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 

And inside the application tag:

  <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/maps_api_key" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 

I request runtime permissions:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION); } 

And this is the callback:

 @Override public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) { switch (requestCode) { case PERMISSION_REQUEST_COARSE_LOCATION: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { //Access Location } else { Utils.showToast(getApplicationContext(), "Until you grant the permissions, You cannot Access Location Service"); } } break; } } 

I get this exception

"android.view.InflateException: Binary XML file line #: Error inflating class fragment" only on Android 6.

It displays the map without any problems in the rest of the Android versions. Please help me.

+6
source share
2 answers

Do you have an SD card on your Android-M device? If not, insert an SD card and try again.

+1
source

I can not find anything strange in xml. However, a mistake with inflation can occur not only on this layout. For example, this xml layout includes toolbar_layout, maybe the error is in toolbar_layout.xml.

I suppose that perhaps you can mark some tags and try again, and finding the find tag raise this exception.

+1
source

All Articles