Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splash screen error: android.content.res.Resources$NotFoundException: Drawable

I'm trying to implement a splash screen to my android app by following this article. I've followed it step by step but whenever i try to run the app, it instantly crashes and i get the following error in my logcat:

2019-01-05 10:46:33.682 2265-2265/com.example.khoi.parkingapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.khoi.parkingapp, PID: 2265
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.khoi.parkingapp/com.example.khoi.parkingapp.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable com.example.khoi.parkingapp:drawable/splash_background with resource ID #0x7f07008d
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.khoi.parkingapp:drawable/splash_background with resource ID #0x7f07008d
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_background.xml from drawable resource ID #0x7f07008d
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:837)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659)
        at android.content.res.Resources.getDrawableForDensity(Resources.java:891)
        at android.content.res.Resources.getDrawable(Resources.java:833)
        at android.content.Context.getDrawable(Context.java:605)
        at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:463)
        at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
        at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
        at android.support.v7.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
        at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
        at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
        at com.example.khoi.parkingapp.SplashActivity.onCreate(SplashActivity.kt:10)
        at android.app.Activity.performCreate(Activity.java:7183)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     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:146)
        at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1322)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1311)
        at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:284)
        at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:194)
        at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:146)
        at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1322)
2019-01-05 10:46:33.682 2265-2265/com.example.khoi.parkingapp E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1281)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:824)
            ... 24 more

Here is my splash_background.xml

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

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

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

</layer-list>

Any help would be appreciated

like image 433
Barcode Avatar asked Jan 05 '19 15:01

Barcode


People also ask

When is the splash screen dismissed in Android?

The splash screen is dismissed as soon as your app draws its first frame. If you need to load a small amount of data such as in-app settings from a local disk asynchronously, you can use ViewTreeObserver.OnPreDrawListener to suspend the app to draw its first frame.

How does the Google privacy policy handle splashscreen data?

The Google Privacy Policy describes how data is handled in this service. By default, SplashScreen uses the windowBackground of your theme if it's a single color and the launcher icon. The customization of the splash screen is done by adding attributes to the app theme.

How do I customize the splash screen for my App?

By default, SplashScreen uses the windowBackground of your theme if it's a single color and the launcher icon. The customization of the splash screen is done by adding attributes to the app theme. You can specify the following attributes in your Activity theme to customize the splash screen for your app.


1 Answers

Thanks to Alexander for narrowing down the error, I found this post that fixes exactly my issue:

I fixed my splash_background.xml to this:

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

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

</layer-list>

Apparently, the src you need needs to be in the drawable folder and it has be a .png not a .xml

like image 90
Barcode Avatar answered Oct 14 '22 06:10

Barcode