I am parsing images from XML and show it in My Android Application. my problem is when parse more than 20 image the following error occur…
06-09 14:28:37.710: ERROR/AndroidRuntime(490): java.lang.RuntimeException: An error occured while executing doInBackground()
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at java.lang.Thread.run(Thread.java:1096)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
06-09 14:28:37.710: ERROR/AndroidRuntime(490): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:657)
I had the same problem once when thumbnailing images for a file editor I made. What you want to do is shrink the images before storing them to memory, and disposing of the source images from system memory once they have been read
Here is the code I used for mine, it shrinks the images to 110×110, but you can set up your own algorithm to scale it (I believe there is actually already a function for that within the resizedbitmap class, but I havent used it)