Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sometimes: <nine-patch> requires a valid src attribute

I sometimes get reports of this error shown above in my applications. I never see this error during development and test. The applications is for 2.1 and higher. I test in 2.1, 2.2 and 2.3 (emulator) and real devices (except 2.3).

Here's the part of a layout file that produces this error (the view is part of a TableLayout):

 <TextView
 style="@style/ActivityTitleBar"
 android_layout_span="2"
 android:layout_weight="2"
 android:text="@string/txt_appname" />

Here's the style definition:

<style name="ActivityTitleBar">
<item name="android:background">@drawable/titlebar</item>
<item name="android:gravity">center</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">#fff</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>

In res/drawable is a XML file with this content:

<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="@drawable/titlebar" />

The titlebar.png is located in my drawable-hdpi, drawable-ldpi and drawable-mdpi folders.

I don't have any clue what device or Android release causes this error.

Any ideas?

Many thanks in advance.

HJW

Here's the stack-trace-report:

java.lang.RuntimeException: Unable to start activity ComponentInfo{de.x.y.android/de.x.y.android.Main}: android.view.InflateException: Binary XML file line #18: Error inflating class android.widget.TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class android.widget.TextView
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
at android.app.Activity.setContentView(Activity.java:1654)
at de.x.y.android.MyActivity.onCreate(MyActivity.java:46)
at de.X.Y.android.Main.onCreate(Main.java:190)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.TextView.<init>(TextView.java:332)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 25 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/titlebar.xml from drawable resource ID #0x7f020003
at android.content.res.Resources.loadDrawable(Resources.java:1697)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1885)
at android.widget.TextView.<init>(TextView.java:338)
... 29 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: <nine-patch> requires a valid src attribute
at android.graphics.drawable.NinePatchDrawable.inflate(NinePatchDrawable.java:262)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
at android.content.res.Resources.loadDrawable(Resources.java:1694)
... 32 more
like image 720
Harald Wilhelm Avatar asked Jan 05 '11 12:01

Harald Wilhelm


1 Answers

You cannot reliably have both titlebar.xml and titlebar.png. Please rename one to have a different base name.

like image 187
CommonsWare Avatar answered Oct 13 '22 11:10

CommonsWare