我从 android 开始,我想按照 in this answer 的描述为单元格添加边框。所以我创建了我的 cell_background.xml 文件,Eclipse 在 res\drawable
中创建了该文件,其中包含
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="#000"/>
<stroke android:width="1dp" android:color="#ff9"/>
</shape>
读到 drawable 文件夹存在几个问题后,我将其逐字复制到 res\drawable-*dpi
目录
现在,我的应用程序在以下行中崩溃
Drawable drawable = Resources.getSystem().getDrawable(R.drawable.cell_background);
除了这个异常(exception)
12-16 14:26:28.624: E/AndroidRuntime(533): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020000
项目和模拟器都设置为v3.0
有什么想法吗?我已经清理并重建了项目,但它仍然崩溃。
最佳答案
问题在于您使用了 Resources.getSystem(),它将为您提供对系统资源的引用。您应该改用 context.getResources()。
关于android - 查找 Drawable 资源时出现 NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8535626/