• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Bitmap not loading

23tony

Well-Known Member
I'm having a problem with a bitmap not loading after trying to change from a view to a background theme splash page.

For reference, I'm using the splash screen method given at https://www.bignerdranch.com/blog/splash-screens-the-right-way/

I must be missing something but I'm not seeing what.

Here are the relvant files:
styles.xml
Code:
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

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

</resources>

Manifest (relevant parts):
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.poc.justamap">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity" android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
        </activity>

    </application>

</manifest>

MainActivity:
Code:
public class MainActivity extends AppCompatActivity {

    private Handler mHandler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                loadHomePage();
            }
        },5000);
    }

    private void loadHomePage() {
        Intent nextPage = new Intent(MainActivity.this, MapsActivity.class);
        MainActivity.this.startActivity(nextPage);
    }
}
(I'm delaying right now just so I can really see the splash screen)

It's failing on onCreate, saying the bitmap needs a valid src attribute. I've checked, ic_launcher is there, and I've verified that it's a valid image file. I WAS using it previously when I was just loading MainActivity and pausing for a second - that worked ok. It has only stopped working since I made this update.

Stack trace:
Code:
I/InstantRun: starting instant run server: is main process
D/skia: --- SkAndroidCodec::NewFromStream returned null
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.poc.justamap, PID: 6708
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.poc.justamap/com.poc.justamap.MainActivity}: android.content.res.Resources$NotFoundException: Drawable com.poc.justamap:drawable/splash_screen with resource ID #0x7f06007d
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        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:767)
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.poc.justamap:drawable/splash_screen with resource ID #0x7f06007d
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f06007d
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:768)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:600)
        at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
        at android.content.res.Resources.getDrawable(Resources.java:818)
        at android.content.Context.getDrawable(Context.java:605)
        at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
        at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
        at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
        at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
        at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
        at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
        at com.poc.justamap.MainActivity.onCreate(MainActivity.java:14)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        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:767)
     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)
        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:758)
           ... 24 more

Can anyone see what I'm doing wrong here?
 
So I got it working, by pointing at ic_launcher_foreground instead of ic_launcher

They are both pngs, just somewhat different sizes. I'm not understanding why one worked and the other didn't. Can anyone offer some insight? There's obviously something for me to learn here!
 
Back
Top Bottom