1. Are you ready for the Galaxy S20? Here is everything we know so far!

Bitmap not loading

Discussion in 'Android Development' started by 23tony, Aug 7, 2019.

  1. 23tony

    23tony Well-Known Member
    Thread Starter

    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 (Text):
    1. <resources>
    2.  
    3.     <!-- Base application theme. -->
    4.     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    5.         <!-- Customize your theme here. -->
    6.         <item name="colorPrimary">@color/colorPrimary</item>
    7.         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    8.         <item name="colorAccent">@color/colorAccent</item>
    9.     </style>
    10.  
    11.     <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    12.         <item name="android:windowBackground">@drawable/splash_screen</item>
    13.     </style>
    14.  
    15. </resources>
    Manifest (relevant parts):
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.     xmlns:tools="http://schemas.android.com/tools"
    4.     package="com.poc.justamap">
    5.  
    6.     <application
    7.         android:allowBackup="true"
    8.         android:icon="@mipmap/ic_launcher"
    9.         android:label="@string/app_name"
    10.         android:roundIcon="@mipmap/ic_launcher_round"
    11.         android:supportsRtl="true"
    12.         android:theme="@style/AppTheme">
    13.  
    14.         <activity android:name=".MainActivity" android:theme="@style/SplashTheme">
    15.             <intent-filter>
    16.                 <action android:name="android.intent.action.MAIN" />
    17.                 <category android:name="android.intent.category.LAUNCHER" />
    18.             </intent-filter>
    19.         </activity>
    20.  
    21.         <activity
    22.             android:name=".MapsActivity"
    23.             android:label="@string/title_activity_maps">
    24.         </activity>
    25.  
    26.     </application>
    27.  
    28. </manifest>
    MainActivity:
    Code (Text):
    1. public class MainActivity extends AppCompatActivity {
    2.  
    3.     private Handler mHandler = new Handler();
    4.  
    5.     @Override
    6.     public void onCreate(Bundle savedInstanceState) {
    7.         super.onCreate(savedInstanceState);
    8.         mHandler.postDelayed(new Runnable() {
    9.             @Override
    10.             public void run() {
    11.                 loadHomePage();
    12.             }
    13.         },5000);
    14.     }
    15.  
    16.     private void loadHomePage() {
    17.         Intent nextPage = new Intent(MainActivity.this, MapsActivity.class);
    18.         MainActivity.this.startActivity(nextPage);
    19.     }
    20. }
    (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 (Text):
    1. I/InstantRun: starting instant run server: is main process
    2. D/skia: --- SkAndroidCodec::NewFromStream returned null
    3. D/AndroidRuntime: Shutting down VM
    4. E/AndroidRuntime: FATAL EXCEPTION: main
    5.     Process: com.poc.justamap, PID: 6708
    6.     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
    7.         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
    8.         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    9.         at android.app.ActivityThread.-wrap11(Unknown Source:0)
    10.         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    11.         at android.os.Handler.dispatchMessage(Handler.java:105)
    12.         at android.os.Looper.loop(Looper.java:164)
    13.         at android.app.ActivityThread.main(ActivityThread.java:6541)
    14.         at java.lang.reflect.Method.invoke(Native Method)
    15.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    16.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    17.      Caused by: android.content.res.Resources$NotFoundException: Drawable com.poc.justamap:drawable/splash_screen with resource ID #0x7f06007d
    18.      Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f06007d
    19.         at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:768)
    20.         at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:600)
    21.         at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
    22.         at android.content.res.Resources.getDrawable(Resources.java:818)
    23.         at android.content.Context.getDrawable(Context.java:605)
    24.         at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
    25.         at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
    26.         at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
    27.         at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
    28.         at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
    29.         at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
    30.         at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
    31.         at com.poc.justamap.MainActivity.onCreate(MainActivity.java:14)
    32.         at android.app.Activity.performCreate(Activity.java:6975)
    33.         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
    34.         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    35.         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    36.         at android.app.ActivityThread.-wrap11(Unknown Source:0)
    37.         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    38.         at android.os.Handler.dispatchMessage(Handler.java:105)
    39.         at android.os.Looper.loop(Looper.java:164)
    40.         at android.app.ActivityThread.main(ActivityThread.java:6541)
    41.         at java.lang.reflect.Method.invoke(Native Method)
    42.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    43.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    44.      Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8: <bitmap> requires a valid 'src' attribute
    45.         at android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:823)
    46.         at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:754)
    47.         at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
    48.         at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
    49.         at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1284)
    50.         at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:279)
    51.         at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:194)
    52.         at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
    53.         at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
    54.         at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
    55.         at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:758)
    56.            ... 24 more
    Can anyone see what I'm doing wrong here?
     

    Advertisement

  2. 23tony

    23tony Well-Known Member
    Thread Starter

    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!
     
Loading...

Share This Page

Loading...