0

I use a theme-based solution as it described here, for example, to show a splash screen in my application.
Here is my background_launch.xml:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/launch_image"
android:tileMode="disabled" />

When I have launch_image as png everything is OK. But the app crashes if I use @drawable/layerlist instead of @drawable/launch_image.
layerlist.xml is:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/launch_image"
            android:tileMode="disabled" >
        </bitmap>
    </item>
</layer-list>

The app crashed with the following log (several lines are skipped):

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.glu.pathlight/com.glu.pathlight.JSFinalNativeActivity}: android.content.res.Resources$NotFoundException: File res/drawable/background_launch.xml from drawable resource ID #0x7f020000
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        ...
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/background_launch.xml from drawable resource ID #0x7f020000
    at android.content.res.Resources.loadDrawable(Resources.java:2096)
    at android.content.res.Resources.getDrawable(Resources.java:700)
    ... 11 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: <bitmap> requires a valid src attribute
    at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:571)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
    at android.content.res.Resources.loadDrawable(Resources.java:2092)
    ... 22 more

What is wrong in my resources?

Community
  • 1
  • 1
deko
  • 2,534
  • 3
  • 34
  • 48
  • 5
    this question is misleading, you are asking about using resources and embedding an image inside a layerlist not asking how to center an image inside the screen – Omar HossamEldin Apr 08 '14 at 14:38
  • 2
    ` requires a valid src attribute` because you are passing `layer-list` in `src` of `` instead of image drawable name – ρяσѕρєя K Apr 08 '14 at 14:40
  • 1
    The problem is that background_launch.xml was not found. What resource is referencing that? Perhaps you need to clean your project and build it again. – Jim Rhodes Apr 08 '14 at 14:47
  • @3amoura You may be right. From the one side the question is about using resources, but from the other it solves a particular case I faced. Feel free to suggest another header for this question, I'm ready to change it for the future reference. – deko Apr 09 '14 at 09:20

2 Answers2

2

Put this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/launch_image"
        android:tileMode="disabled" >
    </bitmap>
</item>
</layer-list>

in your background_launch.xml instead of trying to reference a state list in android:src for <bitmap\>

A state list is not a bitmap -- that's what the error's telling you.

Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
0

Check if you have changed android:src="@drawable/launch_image" to android:src="@drawable/layerlist".

Garcia
  • 36
  • 3