代码之家  ›  专栏  ›  技术社区  ›  Ashvin solanki

android.view.InflateException系统:二进制XML文件行#2:膨胀类时出错<unknown>)

  •  -2
  • Ashvin solanki  · 技术社区  · 8 年前
     UnknownException: (Unable to start activity ComponentInfo{*.*.lordshivahdwallpapers/.*.lordshivahdwallpapers.activity.ImageLodingValues}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>)
    at android.view.LayoutInflater.createView(LayoutInflater.java:623)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:699)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:472)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at *.*.lordshivahdwallpapers.activity.ImageLodingValues.onCreate(ImageLodingValues.java:58)
    at android.app.Activity.performCreate(Activity.java:5242)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
    at android.app.ActivityThread.access$800(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5113)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
    at dalvik.system.NativeStart.main(Native Method)
    java.lang.RuntimeException: (Unable to start activity ComponentInfo{com.gauravkhannamarketeer.lordshivahdwallpapers/com.gauravkhannamarketeer.lordshivahdwallpapers.activity.ImageLodingValues}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
    at android.app.ActivityThread.access$800(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5113)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
    at dalvik.system.NativeStart.main(Native Method)
    

    XML文件

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/mahadev_imagesbg"
        tools:context="*.*.activity.ImageLodingValues" >
    
    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/header"
        android:gravity="center">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:fontFamily="@font/roboto_thin"
            android:text="Mahadev Images"
            android:textAlignment="center"
            android:textColor="@android:color/white"
            android:textSize="30sp" />
    </RelativeLayout>
    
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/relativeLayout6"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/relativeLayout3">
    
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/masonry_grid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    </android.support.v4.widget.SwipeRefreshLayout>
    
    
    
    <include
        android:id="@+id/include2"
        layout="@layout/google_ad"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    
    <RelativeLayout
        android:id="@+id/relativeLayout6"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/text_layer"
        app:layout_constraintBottom_toTopOf="@+id/include2"
        tools:layout_editor_absoluteX="25dp">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Pull Down To Refresh"
            android:textAlignment="center"
            android:textColor="@android:color/white"
            android:textSize="20sp" />
    </RelativeLayout>
    </android.support.constraint.ConstraintLayout>
    

    谷歌广告XML文件

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
    <com.google.android.gms.ads.AdView 
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad"
        ads:layout_constraintEnd_toEndOf="parent"
        ads:layout_constraintStart_toStartOf="parent">
    
    </com.google.android.gms.ads.AdView>
    </android.support.constraint.ConstraintLayout>
    

    建筑.梯度

    apply plugin: 'com.android.application'
    
    
    android {
        compileSdkVersion 27
        defaultConfig {
            applicationId "*****"
            minSdkVersion 19
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/ASL2.0'
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        implementation 'com.android.support:design:27.1.1'
        implementation 'com.android.support:support-vector-drawable:27.1.1'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
        implementation 'com.android.support:recyclerview-v7:27.1.1'
        implementation group: 'com.google.http-client', name: 'google-http-client', version: '1.23.0'
        implementation 'com.android.support:support-v4:27.1.1'
        implementation 'com.android.support:cardview-v7:27.1.1'
        implementation 'com.pnikosis:materialish-progress:1.0'
        implementation 'com.google.android.gms:play-services-ads:15.0.1'
        implementation 'com.flurry.android:analytics:11.1.0@aar'
        implementation 'com.startapp:inapp-sdk:3.8.4'
        implementation 'com.facebook.android:audience-network-sdk:4.+'
    }
    

    为什么会出现这个错误任何人都知道

    未知异常:(无法启动活动组件信息{Gauravkhannamarkeer网站.lordshivahdwallpapers先生/Gauravkhannamarkeer网站.l.公司ordshivahdwallpapers.activity.imageloding值}: android.view.InflateException系统:二进制XML文件行#2:类膨胀时出错)

    崩溃端口报告了错误 出现错误

    分区OS:4.4.4 设备型号:红米2(红米2) Divice子模型:2014818

    提前谢谢

    1 回复  |  直到 7 年前
        1
  •  2
  •   Tejas Pandya    8 年前

    首先从你的错误日志

    android.view.InflateException系统:二进制XML文件行#2:错误 充气类)

    看来你对ConstraintLayout有点问题。但是您已经正确地包含了库,以及xml中正确地提到的约束布局。

    所以这个密码可能有一个问题。

     android:background="@drawable/mahadev_imagesbg"
    

    在运行时,Android根据需要调整图像大小(基于屏幕大小和分辨率)。它使用位图在内部进行大小调整。这是非常强的记忆力。所以你的设备 红米2号(红米2号) 内存有问题,正在生成错误。

    因此,尝试一种解决方案:将此(mahadev_imagesbg)图像复制到可绘制的ldpi、mdpi、hdpi文件夹中,然后使用该设备再次测试它。或者尝试低分辨率图像。 也许它能解决你的问题。