加载活动时,android.content.res.Resources $ NotFoundException

时间:2019-01-10 11:43:41

标签: java android xml

在我的应用程序开始时,应该显示启动活动,但是在加载位于“ src / drawabe / background_splash.xml”中的某个可绘制对象时,我总是会遇到以下异常:

E/AndroidRuntime: [ERB] CRASH: main in de.jzbor.epos.debug(11450)
E/AndroidRuntime: FATAL EXCEPTION: main
              Process: de.jzbor.epos.debug, PID: 11450
              java.lang.RuntimeException: Unable to start activity ComponentInfo{de.jzbor.epos.debug/de.jzbor.epos.activities.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable de.jzbor.epos.debug:drawable/background_splash with resource ID #0x7f07005c
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2891)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2969)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1658)
                  at android.os.Handler.dispatchMessage(Handler.java:108)
                  at android.os.Looper.loop(Looper.java:206)
                  at android.app.ActivityThread.main(ActivityThread.java:6735)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)
               Caused by: android.content.res.Resources$NotFoundException: Drawable de.jzbor.epos.debug:drawable/background_splash with resource ID #0x7f07005c
               Caused by: android.content.res.Resources$NotFoundException: File res/drawable/background_splash.xml from drawable resource ID #0x7f07005c
                  at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:910)
                  at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:680)
                  at android.content.res.Resources.getDrawableForDensity(Resources.java:992)
                  at android.content.res.Resources.getDrawable(Resources.java:928)
                  at android.content.Context.getDrawable(Context.java:605)
                  at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
                  at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:87)
                  at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:128)
                  at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
                  at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
                  at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
                  at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:31)
                  at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:31)
                  at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
                  at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
                  at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                  at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70)
                  at de.jzbor.epos.activities.SplashActivity.onCreate(SplashActivity.java:11)
                  at android.app.Activity.performCreate(Activity.java:6975)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2844)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2969)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1658)
                  at android.os.Handler.dispatchMessage(Handler.java:108)
                  at android.os.Looper.loop(Looper.java:206)
                  at android.app.ActivityThread.main(ActivityThread.java:6735)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)
               Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8: <bitmap> requires a valid 'src' attribute
                  at android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:823)
                  at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:754)
                  at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
                  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1284)
                  at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:279)
                  at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:194)
                  at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
                  at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
                  at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
                  at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:897)
                    ... 30 more

styles.xml

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

background_splash.xml

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

<item
    android:drawable="@color/primaryColor"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher"/>
</item>

它可能与构建配置中的“ .debug”后缀有关,但是我找不到解决方法。

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug {
        applicationIdSuffix ".debug"
        debuggable true
    }

}

[编辑] 因此,感谢您的帮助(尤其是@kvaruna),我发现问题出在位图上。有人知道在那里是否可以使用位图以及如何避免该错误吗?

0 个答案:

没有答案