android.view.InflateException:二进制XML文件:错误膨胀类片段 [英] android.view.InflateException: Binary XML file : Error inflating class fragment

查看:114
本文介绍了android.view.InflateException:二进制XML文件:错误膨胀类片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android Studio 在android应用中使用 GoogleMap 。它工作正常,不知道为什么突然停止工作。 minSdkVersion是15,targetSdkVersion是24.请检查我的下面的代码并帮助我解决这个问题:



XML:

 < FrameLayout xmlns:android =http://schemas.android.com/apk/res/android
xmlns:tools =http://schemas.android.com/tools
android:layout_width =match_parent
android:layout_height =match_parent>

<片段
android:id =@ + id / mapFragment
class =com.google.android.gms.maps.SupportMapFragment
android :layout_width =match_parent
android:layout_height =match_parent/>

< / FrameLayout>

Gridle:

 依赖关系{
编译fileTree(包括:['* .jar'],dir:'libs')
testCompile'junit:junit:4.12'
compile'c​​om.android.support:appcompat-v7:24.2.0'
compile'c​​om.android.support:design:24.2.0'
compile'c​​om.google.android.gms :play-services:9.4.0'
compile'c​​om.google.maps.android:android-maps-utils:0.4.3'
compile'c​​om.loopj.android:android-async-http :1.4.9'
compile'c​​om.google.code.gson:gson:2.7'
compile'c​​om.googlecode.android-query:android-query:0.24.3'
compile 'com.makeramen:roundedimageview:2.2.1'
}

Java:

  public class MapsActivity扩展Fragment实现的OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient。 OnConnectionFailedList (
LocationListener {
@Override
public ViewView onCreateView(LayoutInflater inflater,ViewGroup container,
Bundle savedInstanceState){
SupportMapFragment mapFragment =(SupportMapFragment)getChildFragmentManager()
.findFragmentById(R.id.mapFragment);


清单:

 <元数据
android:name =com.google.android.gms.version
android:value =@ integer / google_play_services_version/>
< meta-data
android:name =com.google.android.maps.v2.API_KEY
android:value =@ string / google_maps_key/>

错误:

它在xml中发生错误,位于< fragment ,错误: android.view.InflateException:二进制XML文件: / code>

解决方案

在清单中添加权限后,它解决了我的问题。请检查以下代码:

 < uses-permission 
android:name =android.permission.WRITE_EXTERNAL_STORAGE
android:maxSdkVersion =24/>
<使用权限
android:name =android.permission.READ_EXTERNAL_STORAGE
android:maxSdkVersion =24/>


I am using GoogleMap in android app using Android Studio. It was working fine and don't know why suddenly it stopped working. minSdkVersion is 15 and targetSdkVersion is 24. Please check my below code and help me to come out of this :

XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

</FrameLayout>

Gridle:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.maps.android:android-maps-utils:0.4.3'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.googlecode.android-query:android-query:0.24.3'
    compile 'com.makeramen:roundedimageview:2.2.1'
}

Java:

    public class MapsActivity extends Fragment implements OnMapReadyCallback,
            GoogleApiClient.ConnectionCallbacks,
            GoogleApiClient.OnConnectionFailedListener,
            LocationListener {
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
          SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
                        .findFragmentById(R.id.mapFragment);
          }
    }

Manifest:

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

Error:

It is giving error in xml at <fragment, error: android.view.InflateException: Binary XML file : Error inflating class fragment

解决方案

After adding permission in manifest, It solved my issue. Check below code :

<uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="24" />
<uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="24" />

这篇关于android.view.InflateException:二进制XML文件:错误膨胀类片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆