-1
for (int k = 0; k < file.length; k++) {
        Bitmap myBitmap= null;
        myBitmap = BitmapFactory.decodeFile(file[k].getAbsolutePath());
        bitMap.add(myBitmap);

}

My App is crashing when i am using this code for storing all image in bitmap Arraylist, For lesser number of image it works fine, but for more then 30 images it crashing.

AMIT
  • 390
  • 1
  • 4
  • 17
  • What size are the images? – Simon Jan 09 '15 at 12:29
  • possible duplicate of [Strange out of memory issue while loading an image to a Bitmap object](http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object) – Simon Jan 09 '15 at 12:33

2 Answers2

0

If you look here

http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeFile%28java.lang.String%29,

you'll find out that decodeFile can return null. Therefore, you should check myBitmap before using it

You'll find this interesting as well:

Community
  • 1
  • 1
Danilo Gasques
  • 666
  • 6
  • 16
0

For lesser number of image it works fine, but for more then 30 images it crashing

Sounds like you are getting out of memory.. Not a NPE as someone mentioned in his answere. Use smaller images and scale them up when needed. Would be my first suggest without seeing logcat. Hope it helps.

Mike
  • 857
  • 1
  • 7
  • 11