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


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>

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: 错误膨胀类(

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

潜水操作系统:4.4.4 设备型号:红米2(红米2( 分部子模型:2014818

提前致谢

首先来自您的错误日志

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

似乎您对约束布局有某种问题。 但是您已经正确包含库,以及正确提及XML中的约束布局。

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

android:background="@drawable/mahadev_imagesbg"

在运行时,Android 会根据需要(基于屏幕尺寸和分辨率(调整图像大小。它使用位图在内部调整大小。这是非常 内存密集型 .所以您的设备红米2(红米2(有内存问题,它正在生成错误。

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

最新更新