android - Android 错误膨胀 ImageView - ResourcesNotFoundException
问题描述
我在我发布的应用程序崩溃报告中发现了这个异常。在我的设备上,在调试期间,在模拟器上都不会发生错误。它仅在为某些用户发布应用程序后发生,目前他们使用 Nexus 4 设备(来自 Crashlytics 的信息)。
这是报告:
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{InfoActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: **Error inflating class ImageView**
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2419)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2479)
android.app.ActivityThread.-wrap11 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1347)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5421)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
和这个:
Caused by android.view.InflateException
Binary XML file line #13: Binary XML file line #13: Error inflating class ImageView
android.view.LayoutInflater.inflate (LayoutInflater.java:539)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
android.view.LayoutInflater.inflate (LayoutInflater.java:374)
androidx.appcompat.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:545)
androidx.appcompat.app.AppCompatActivity.setContentView (AppCompatActivity.java:161)
InfoActivity.onCreate (InfoActivity.java:45)
android.app.Activity.performCreate (Activity.java:6280)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1116)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2372)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2479)
android.app.ActivityThread.-wrap11 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1347)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5421)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
它指向InfoActivity.onCreate (InfoActivity.java:45)
我的 InfoActivity.java 中的哪一行:setContentView(R.layout.activity_info);
在 activity_info 布局中,我有一个 ImageView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="#DBDBDB">
<ImageView
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="@string/logo"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/logo" />
除了常见的可绘制文件夹外,我在所有可绘制文件夹(hdpi、mdpi、xhdpi 等)中都有 logo.png 图像。
这种崩溃只发生在 Nexus 4 上的用户身上,也发生在另一个活动中,我有一个带有可绘制图像的按钮。
我还尝试将所有图像也移动到空的 ldpi 文件夹中,但我现在无法复制它,因为它仅适用于 Nexus 4。
不确定是什么导致了这种情况,因为除了主要可绘制对象之外的所有文件夹中都存在可绘制资源。我正在考虑将图像例如从 xdpi 放到公共可绘制文件夹中,但不确定这是否有帮助。
摇篮:
android {
compileSdkVersion 29
defaultConfig {
applicationId "***"
minSdkVersion 23
targetSdkVersion 29
versionCode 12
versionName "2.02"
ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
bundle {
language {
enableSplit = false
}
}
}
解决方案
推荐阅读
- c# - ASP.NET 对模型的空引用
- javascript - 如何使我的字母对单词的顺序不敏感
- asp.net - 尝试使用带有 ASP.NET 身份的 cookie 身份验证登录时获取 HTTP 500
- gradle - 使用 VSCode 和 Flutter 构建 appbundle 的问题
- html - 在我的导航 div 中嵌套一个无序列表
- python - 在python中逐行浏览数组
- flutter - Flutter Transform.rotate 如何在按下按钮时使其工作,而不是自动
- docker - 在 Dockerfile 和 docker-compose.yml 中编写什么代码以在 docker 环境中传递本地包
- mediawiki - 在 Mediawiki 图片库或表格中使用分页
- java - 使用大量数据提高休眠插入性能的最佳方法