开发者

Android State List Parsing Error

The following code throws this error...

<item> line #3 requires a 'drawable' attribute or a child tag defining a drawable at androi开发者_高级运维d.graphics.(continued)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/button-background-focus" /> <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/button-background-focus" /> <!-- focused -->
    <item android:drawable="@drawable/button-background" /> <!-- default -->
</selector>

The drawable attribute is right there, it is a picture for a button. I have used this same pic as a drawable in other places, it is only when I try to use this xml file as a drawable do I get the above error.

How can I fix this error?

--UPDATE--

This is the block of code that is throwing the exception (in class StateListDrawable)

if (drawableRes != 0) {
                        dr = r.getDrawable(drawableRes);
                    } else {
                        while ((type = parser.next()) == XmlPullParser.TEXT) {
                        }
                        if (type != XmlPullParser.START_TAG) {
                            throw new XmlPullParserException(
                                    parser.getPositionDescription()
                                            + ": <item> tag requires a 'drawable' attribute or "
                                            + "child tag defining a drawable");
                        }
                        dr = Drawable.createFromXmlInner(r, parser, attrs);

The state list code from the Android API can be found Here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜