[英]Drawable Resource Not Found
我正在嘗試為自定義ArrayAdapter
實現選擇器可繪制資源。 我一直得到一個android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020
有人可以提供建議嗎?
我有兩個 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
<?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>
最后,我的代碼按如下方式加載列表項:
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;
}
看看@Nebraska 的建議是否有幫助。
否則,試試這個:
<?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>
首先,將它們放在hdpi文件夾中,然后清理項目。 它將更新所有內容,錯誤應該消失。
另一種解決方案是我將 XML drawables 移動到 drawable/ 文件夾,它對我來說非常好。 您可能想嘗試一下。
KitKat 及以下的 VectorDrawableCompat Resources$NotFoundException
對我來說,困惑是我已經用 png 替換了矢量可繪制的所有實例,除了一個,這就是失敗的原因。 確保並檢查給您帶來問題的資源的所有實例,並且一切都按預期進行...
我遇到了類似的問題,我能夠通過刪除 .xml drawable 頂部的空行來修復它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.