寻找可绘制资源时NotFoundException [英] NotFoundException when looking for Drawable resource

查看:156
本文介绍了寻找可绘制资源时NotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始与Android,我想描述的在这个答案。所以,我创建了cell_background.xml文件,Eclipse在水库创建\\绘制并包含

I am starting with android and I want to add a border to cells as described in this answer. So I created my cell_background.xml file, which Eclipse created in res\drawable and that contains

<?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- * DPI 目录

现在,下面这行我的应用程序崩溃

Now, my app crashes in the following line

Drawable drawable = Resources.getSystem().getDrawable(R.drawable.cell_background);

与此异常

12-16 14:26:28.624: E/AndroidRuntime(533): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020000

这两个项目和仿真器设置为3.0

Both the project and the emulator are set to v3.0

任何想法?我已经清理和重建项目,但它仍然崩溃。

Any ideas? I have already cleaned and rebuilt the project but it still crashes.

推荐答案

的问题是,你使用Resources.getSystem(),它会给你的系统资源的引用。您应该使用context.getResources()代替。

The problem is that you use Resources.getSystem(), which will give you a reference to the system resources. You should use context.getResources() instead.

这篇关于寻找可绘制资源时NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆