![](/img/trans.png)
[英]android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
[英]android.view.InflateException: Binary XML file line #2: Error inflating class <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>
構建.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 設備型號:紅米2(Redmi 2) 設備子型號:2014818
提前致謝
首先來自您的錯誤日志
android.view.InflateException:二進制 XML 文件第 2 行:錯誤膨脹類)
您似乎對 ConstraintLayout 有某種問題。 但是你已經正確地包含了庫,以及在 xml 中正確提到的約束布局。
所以這段代碼可能有一個問題。
android:background="@drawable/mahadev_imagesbg"
在運行時,Android 根據需要(基於屏幕大小和分辨率)調整圖像大小。 它使用 Bitmap 進行內部調整大小。 這是非常內存密集的。 所以你的設備紅米 2(紅米 2)有內存問題,它正在生成錯誤。
因此,嘗試一種解決方案:將此(mahadev_imagesbg)圖像復制到 drawable-ldpi、mdpi、hdpi 文件夾,然后使用該設備再次測試。 或者嘗試使用較低分辨率的圖像。 也許它會解決你的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.