android.view.InflateException:二进制XML文件第2行:错误夸大类<unknown>)

时间:2018-08-27 07:29:00

标签: java android

 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>
  

GOOGLE AD 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>
  

Build.Gradle

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.+'
}

为什么这个错误来自任何人

UnknownException :(无法启动活动ComponentInfo {com.gauravkhannamarketeer.lordshivahdwallpapers / com.gauravkhannamarketeer.lordshivahdwallpapers.activity.ImageLodingValues}:android.view.InflateException:二进制XML文件第2行:膨胀类错误)

CrashReports报告了错误 错误进来

  

Divece OS:4.4.4   设备型号:Hongmi 2(Redmi 2)   Divice子模型:2014818

预先感谢

1 个答案:

答案 0 :(得分:2)

首先从您的错误日志

  

android.view.InflateException:二进制XML文件第2行:错误   充气课)

似乎您的ConstraintLayout存在某种问题。但是您已经适当地包含了库,并且在xml中适当地提到了约束布局。

所以此代码可能有一个发行版。

 android:background="@drawable/mahadev_imagesbg"

在运行时,Android根据需要(根据屏幕大小和分辨率)调整图像大小。它使用Bitmap在内部进行大小调整。这是非常占用内存的。因此,您的设备 Hongmi 2(Redmi 2)出现内存问题,并且正在生成错误。

因此,请尝试一种解决方案:将此(mahadev_imagesbg)图片复制到drawable-ldpi,mdpi,hdpi文件夹,然后使用该设备再次进行测试。否则尝试使用较低分辨率的图像。  也许它将解决您的问题。