Custom Spinner 9-patch causes crash on Motorola Xoom
I have a custom 9-patch image for my spinner. This image works fine on my phone, but causes a crash on a Motorola Xoom. Here is the stack trace:
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): FATAL EXCEPTION: main
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.DealerLocatorActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class android.widget.Spinner
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.ActivityThread.access$500(ActivityThread.java:122)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.os.Looper.loop(Looper.java:132)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.ActivityThread.main(ActivityThread.java:4123)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at java.lang.reflect.Method.invoke(Method.java:491)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at dalvik.system.NativeStart.main(Native Method)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.widget.Spinner
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.createView(LayoutInflater.java:596)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:223)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.Activity.setContentView(Activity.java:1786)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at com.example.myapp.DealerLocatorActivity.onCreate(DealerLocatorActivity.java:30)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.Activity.performCreate(Activity.java:4397)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): ... 11 more
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): Caused by: java.lang.reflect.InvocationTargetException
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at java.lang.reflect.Constructor.constructNative(Native Method)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at java.lang.reflect.Constructor.newInstance(Constructor.java:416)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.view.LayoutInflater.createView(LayoutInflater.java:576)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): ... 25 more
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): Caused by: java.lang.StackOverflowError
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.NinePatchDrawable.setNinePatchState(NinePatchDrawable.java:99)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.NinePatchDrawable.<init>(NinePatchDrawable.java:383)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.NinePatchDrawable.<init>(NinePatchDrawable.java:38)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.NinePatchDrawable$NinePatchState.newDrawable(NinePatchDrawable.java:373)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.getCachedDrawable(Resources.java:1972)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.loadDrawable(Resources.java:1873)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.getDrawable(Resources.java:655)
10-10 15:52:56.487: ERROR/An开发者_C百科droidRuntime(4187): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:832)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:769)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.loadDrawable(Resources.java:1903)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.getDrawable(Resources.java:655)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:832)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:769)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.loadDrawable(Resources.java:1903)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.content.res.Resources.getDrawable(Resources.java:655)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:832)
10-10 15:52:56.487: ERROR/AndroidRuntime(4187): at android.graphics.drawabl
Here is the layout at line 17:
<Spinner
android:id="@+id/spn_dealer_type"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="fill_parent"
style="@style/Widget.Spinner"></Spinner>
Here is the style:
<style
name="Widget.Spinner"
parent="android:Widget">
<item
name="android:background">@drawable/spinner</item>
<item
name="android:clickable">true</item>
</style>
And here is the drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/spinner_light" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/spinner_dark" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/spinner_dark" />
<item
android:drawable="@drawable/spinner" />
</selector>
As I said, this works fine on a phone, but is crashing on the Xoom. Any ideas what is wrong?
This seems a problem:
<item
android:drawable="@drawable/spinner" />
You're referencing a drawable in itself. This is causing a stack overflow.
精彩评论