初始化Drawable时的ResourcesNotFoundException

时间:2011-03-28 13:00:58

标签: android drawable

private Drawable drawable;

drawable = this.getResources().getDrawable(R.drawable.icon);

当我按照我的htc欲望运行它时会发生这种情况,但是当我尝试初始化drawable时,它会在模拟器上崩溃。这是为什么?

编辑:这是我的stacktrace

  03-28 13:27:58.453: ERROR/ActivityThread(888): Failed to find provider info for com.google.settings
03-28 13:28:06.414: ERROR/AndroidRuntime(888): Uncaught handler: thread main exiting due to uncaught exception
03-28 13:28:06.486: ERROR/AndroidRuntime(888): java.lang.RuntimeException: Unable to start activity ComponentInfo{be.test.helloworld/be.test.helloworld.MyMapActivityII}: android.content.res.Resources$NotFoundException: Resource ID #0x7f020000
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.os.Looper.loop(Looper.java:123)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.ActivityThread.main(ActivityThread.java:3948)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at java.lang.reflect.Method.invokeNative(Native Method)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at java.lang.reflect.Method.invoke(Method.java:521)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at dalvik.system.NativeStart.main(Native Method)
03-28 13:28:06.486: ERROR/AndroidRuntime(888): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020000
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.content.res.Resources.getValue(Resources.java:846)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.content.res.Resources.getDrawable(Resources.java:534)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at be.test.helloworld.MyMapActivityII.initOverlays(MyMapActivityII.java:44)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at be.test.helloworld.MyMapActivityII.onCreate(MyMapActivityII.java:38)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
03-28 13:28:06.486: ERROR/AndroidRuntime(888):     ... 11 more

1 个答案:

答案 0 :(得分:1)

确保所有可绘制文件夹中都有一个图标(drawable-ldpi,drawable-mdpi和drawable-hdpi)