I Am working on camera, when I launch the application, activity will be visible for the user and I have a button to call camera intent. I have all my images used in activity in drawable-xxhdpi folder, This will work fine and now I will click the button to capture image and click on save the application crashes by giving Resource not found exception
Then I copied images from drawable-xxhdpi folder to drawable folder, The application works fine, Can anyone tell me the reason why First time Images are taking from drawable-xxhdpi folder and not the second time (After clicking save in camera).
This issue is only coming in Android 5.0.1, and works fine in Android 4.4.2
Any help will be appreciated
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);
crash log
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)
However you solved your issue, this happen due to device size Your Android4.4.2
device uses drawable-xxhdpi
resource folder and your Android 5.0.1
devices may be smaller in size it is searching images in drawable-hdpi
or other resource folder where images are not present so it troughs the exception Resource not found
.
Note:
Issue is not with android versions
Suppose you put your images in drawable-xxhdpi
and your are trying to run your application on Device or emulator which have xxhdpi type device. then it will run. and if your are try to run same application in ldpi
or mdpi
type device then it will crash with ResourceNotFoundException
just because of unavailability of your images in drawable-ldpi , mdpi
,
Punch line
If you will put your images in just drawable
folder then crash will not happen because android will take it for all device regardless from device configuration or type.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.