Binary XML file line #: Error inflating class frag

2019-06-19 03:18发布

I'm not able to show the google map on Android M.

Here is layout xml:

<?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 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'm requesting for permissions at runtime:

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'm getting this exception

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

It is showing map without any issue on rest of the versions of android. Please help me.

2条回答
仙女界的扛把子
2楼-- · 2019-06-19 03:37

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

查看更多
唯我独甜
3楼-- · 2019-06-19 03:37

I can't find any strange in the xml. However, inflation error may not happen only on this layout. For example, this layout xml include toolbar_layout, maybe the error is in toolbar_layout.xml.

I'll suggest that, maybe you can mark out some tags and try again and find out find tag cause this exception.

查看更多
登录 后发表回答