简体   繁体   English

未找到可绘制资源

[英]Drawable Resource Not Found

All I am attempting to implement a selector drawable resource for a custom ArrayAdapter .我正在尝试为自定义ArrayAdapter实现选择器可绘制资源。 I am consistently getting a android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020我一直得到一个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:我有两个 xml 文件:

res/drawable/list_selector.xml 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 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;
    }

See if what @Nebraska has suggested helps.看看@Nebraska 的建议是否有帮助。

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>

First of all, put them in the hdpi folder, and then clean the project.首先,将它们放在hdpi文件夹中,然后清理项目。 It will update everything and the error should be gone.它将更新所有内容,错误应该消失。

An alternate solution is I moved the XML drawables to the drawable/ folder and it worked perfectly fine for me.另一种解决方案是我将 XML drawables 移动到 drawable/ 文件夹,它对我来说非常好。 You might want to give it a try.您可能想尝试一下。

VectorDrawableCompat Resources$NotFoundException on KitKat and below KitKat 及以下的 VectorDrawableCompat Resources$NotFoundException

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.对我来说,困惑是我已经用 png 替换了矢量可绘制的所有实例,除了一个,这就是失败的原因。 make sure and check all instances of the resource that is giving you the issue, and that all is as expected...确保并检查给您带来问题的资源的所有实例,并且一切都按预期进行...

我遇到了类似的问题,我能够通过删除 .xml drawable 顶部的空行来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM