繁体   English   中英

由 android.content.res.Resources$NotFoundException 引起:即使资源存在,资源 ID 也可绘制(缺少名称)

[英]Caused by android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID even the resource is there

在某些 Android 设备上,我收到“Resources$NotFoundException: Drawable (missing name) with resource ID”错误,例如:

在 LGE Android 8.1 设备上它抱怨

Unable to start activity ComponentInfo{SplashActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView

对于以下部分。 特别是抱怨“ android:src="@drawable/red_logo"

    <ImageView
    android:id="@+id/logoImageView"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:layout_marginStart="50dp"
    android:layout_marginEnd="50dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:src="@drawable/red_logo" />

我检查了源代码目录,“red_logo.png”已经存在于以下文件夹中:

  • 可绘制的
  • 可绘制的 hdpi
  • 可绘制的 ldpi
  • 可绘制的 mdpi
  • 可绘制的 xhdpi
  • 可绘制-xxhdpi
  • 可绘制的xxxhdpi

这是Java代码

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash); <---- Fails here
}

drawable文件夹中red_logo.png的尺寸为4864×2692,与drawable-xxxhdpi文件夹中的red_logo.png大小相同。 是不是太大了?

我做了很多研究,但似乎找不到有效的答案。

谢谢你。 此致。

它是由于规模问题而发生的,因此,在这种情况下,始终使用矢量资产而不是图像。 为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM