资源未找到异常在Android 5.0.1中

时间:2015-05-19 05:35:22

标签: android camera drawable android-5.0-lollipop

我在相机上工作,当我启动应用程序时,用户可以看到活动,我有一个按钮来调用相机意图。我在drawable-xxhdpi文件夹中的活动中使用了所有图像,这将正常工作,现在我将单击按钮捕获图像,然后通过提供资源未找到异常

然后我将图像从drawable-xxhdpi文件夹复制到drawable文件夹,应用程序工作正常,任何人都可以告诉我第一次使用drawable-xxhdpi文件夹而不是第二次(在相机中点击保存后)图像的原因

此问题仅适用于Android 5.0.1,并且在Android 4.4.2中运行良好

任何帮助将不胜感激

mainLayout = inflater.inflate(R.layout.inner_fragment_layout_with_header, null);
headerLayout = (RelativeLayout) mainLayout.findViewById(R.id.header);
headerLayout.setBackgroundResource(R.drawable.profile_handheld_header_bg);

崩溃日志

05-19 11:54:44.194: E/AndroidRuntime(14497):    at java.lang.reflect.Method.invoke(Method.java:372)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
05-19 11:54:44.194: E/AndroidRuntime(14497): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02018f
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.content.res.Resources.getValue(Resources.java:2345)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.content.res.Resources.getDrawable(Resources.java:1850)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.content.Context.getDrawable(Context.java:408)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.view.View.setBackgroundResource(View.java:17212)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.cc.android.fragments.BaseFragment.processHeader(BaseFragment.java:147)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.cc.android.fragments.BaseFragment.getViewApplyingHeaderConfiguration(BaseFragment.java:127)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.cc.android.fragments.BaseFragment.onCreateView(BaseFragment.java:103)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.cc.android.fragments.ContentFragment.onCreateView(ContentFragment.java:64)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at roboguice.activity.RoboFragmentActivity.onStart(RoboFragmentActivity.java:60)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.cc.android.activities.BaseActivity.onStart(BaseActivity.java:139)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at com.android.cc.android.activities.RootPotraiteActivity.onStart(RootPotraiteActivity.java:224)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.app.Activity.performStart(Activity.java:6329)
05-19 11:54:44.194: E/AndroidRuntime(14497):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2656)

2 个答案:

答案 0 :(得分:2)

然而,您解决了问题,这是由于设备大小而导致Android4.4.2设备使用drawable-xxhdpi资源文件夹而您的Android 5.0.1设备的尺寸可能会缩小drawable-hdpi 1}}或其他不存在图像的资源文件夹,因此它会超出异常Resource not found

注意:

问题与Android版本无关

答案 1 :(得分:0)

假设您将图像放在drawable-xxhdpi中,并且您正试图在具有xxhdpi类型设备的设备或仿真器上运行您的应用程序。那么它会运行。 如果您尝试在ldpimdpi类型设备中运行相同的应用程序,那么只会因ResourceNotFoundException中的图片不可用而导致drawable-ldpi , mdpi崩溃,

打孔线

如果您将图像放在drawable文件夹中,则不会发生崩溃,因为无论是设备配置还是类型,Android都会将其用于所有设备。