I have three(ABC,PQR,XYZ) buttons in my UI, if i click any button then my application loads different images from drawable
folder , but some time it gives OutOfMemory
Exception
. I am using the following code for loading images from Drawable
folder.
abc.setBackgroundResource(R.drawable.abc_on);
pqr.setBackgroundResource(R.drawable.pqr_off);
xyz.setBackgroundResource(R.drawable.xyz_off);
I am getting following exception in my logcat.
E/AndroidRuntime(22116): java.lang.OutOfMemoryError
E/AndroidRuntime(22116): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(22116): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
E/AndroidRuntime(22116): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
E/AndroidRuntime(22116): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
E/AndroidRuntime(22116): at android.content.res.Resources.loadDrawable(Resources.java:3024)
E/AndroidRuntime(22116): at android.content.res.Resources.getDrawable(Resources.java:1586)
E/AndroidRuntime(22116): at android.view.View.setBackgroundResource(View.java:16144)
E/AndroidRuntime(22116): at com.bloopit.fragments.ABCFragment.onClick(ABCFragment.java:242)
I am using Galaxy s4 device, and placed my images in xxhdpi folder and xml layout file is in layout folder. So, please guide me how to handle this. Thankyou.