致命异常:android.content.res.Resources$NotFoundException:Drawable org.radarcns.detail:drawable/status_searching,资源 ID #0x7f080130

问题描述 投票:0回答:1

我遇到异常:

Fatal Exception: android.content.res.Resources$NotFoundException: Drawable org.radarcns.detail:drawable/status_searching with resource ID #0x7f080130


Caused by android.content.res.Resources$NotFoundException: Resource "org.radarcns.detail:drawable/status_searching" (7f080130) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f080130 a=11 r=0x7f080130}
       at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:828)
       at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:673)
       at android.content.res.Resources.loadDrawable(Resources.java:1002)
       at android.content.res.Resources.getDrawableForDensity(Resources.java:992)
       at android.content.res.Resources.getDrawable(Resources.java:931)
       at android.content.Context.getDrawable(Context.java:810)
       at androidx.core.content.ContextCompat$Api21Impl.getDrawable(ContextCompat.java:1049)
       at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:485)
       at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:149)
       at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:137)
       at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:66)
       at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:91)
       at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:102)
       at org.radarcns.detail.SourceRowView$updateSourceStatus$1.invoke(SourceRowView.kt:155)
       at org.radarcns.detail.SourceRowView$updateSourceStatus$1.invoke(SourceRowView.kt:152)
       at org.radarbase.android.util.ChangeApplier.applyIfChanged(ChangeApplier.kt:72)
       at org.radarcns.detail.SourceRowView.updateSourceStatus(SourceRowView.kt:152)
       at org.radarcns.detail.SourceRowView.display(SourceRowView.kt:148)
       at org.radarcns.detail.MainActivityViewImpl.update$lambda$6(MainActivityViewImpl.kt:157)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7918)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

SourceRowView 中出现此错误的代码如下:

    private val mStatusIcon: ImageView = findViewById(R.id.status_icon)
    mStatusIcon.setImageResource(R.drawable.status_searching)

R.drawable.status_searching 存在于 src/main/res/drawable 中,其中包含:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/ic_searching" />
</layer-list>

现在@drawable/ic_searching.png以png格式存在于drawable-hdpi、drawable-mdpi、drawable-xhdpi和drawable-xxhdpi中。

即使所有资源都存在,但它给出了 ResourceNotFound,我不明白为什么会发生这种情况?

android android-imageview android-xml android-drawable android-resources
1个回答
0
投票

我推荐使用以下功能。

imageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.your_image));
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.