Constantin
Constantin

Reputation: 17758

Drawable Resource Not Found

All I am attempting to implement a selector drawable resource for a custom ArrayAdapter. I am consistently getting a android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020

Could anyone offer suggestions?

I have two xml files:

res/drawable/list_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true" android:color="@android:color/white" />
    <item android:state_checked="false" android:color="@android:color/black" />
</selector>

res/layout/list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView 
        android:id="@+id/casualty_text_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/list_selector"/>

</LinearLayout>

Finally, my code loads the list item as follows:

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        TCCC cur_object = getItem(position);

        View cur_view = convertView;
        if(cur_view == null)
        {
            System.out.println("Inflating!");
            cur_view = View.inflate(getContext(), R.layout.list_item, null);
            String text_value = (cur_object.m_name.length() == 0) ? "New Casualty" : cur_object.m_name;

            TextView name_box = (TextView)cur_view.findViewById(R.id.casualty_text_view);
            if(name_box != null)
                name_box.setText(text_value);
        }

        return cur_view;
    }

Upvotes: 15

Views: 25074

Answers (5)

Herv&#233; Kasparian
Herv&#233; Kasparian

Reputation: 169

I encounter a similar issue, I was able to fix it by removing a blank line at top of a .xml drawable.

Upvotes: 0

jacoballenwood
jacoballenwood

Reputation: 3057

For me the confusion was that I had replaced all instances of a vector drawable with png, except for one, and this is what was failing. make sure and check all instances of the resource that is giving you the issue, and that all is as expected...

Upvotes: 0

remykarem
remykarem

Reputation: 2469

An alternate solution is I moved the XML drawables to the drawable/ folder and it worked perfectly fine for me. You might want to give it a try.

VectorDrawableCompat Resources$NotFoundException on KitKat and below

Upvotes: 0

Vikram
Vikram

Reputation: 51571

See if what @Nebraska has suggested helps.

Else, try this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true" android:drawable="@android:color/white" />
    <item android:state_checked="false" android:drawable="@android:color/black" />
</selector>

Upvotes: 15

verymessi
verymessi

Reputation: 117

First of all, put them in the hdpi folder, and then clean the project. It will update everything and the error should be gone.

Upvotes: 4

Related Questions