Out of Memory Error when Loading Images from Mipmap folder

312 views Asked by At

Logcat FATAL EXCEPTION: main Process: com.example.markpalmer.blackjack21, PID: 21864 java.lang.OutOfMemoryError: Failed to allocate a 5808012 byte allocation with 5226696 free bytes and 4MB until OOM

Hi, I know there are some posts regarding this, but I don't really understand the answers. The error is random, and occurs when setting an imageview:

ivPlayerCard3.setImageResource(picP3);

The images are not large: 36kb, 500x700 .png files. The thing is for no particular reason I have put them in the res>mipmap-hdpi folder. Could this be the reason for my problem. Would shifting them to the drawable folder help? Many thanks in advance.

1

There are 1 answers

3
MadScientist On

Why don't you try setting thee imageResouce using well known libraries like Picasso check the doc here

Picasso handles OOM very well by loading the image in segments or fractions. Also moving them to drawable might help as mipmap actually creates a map of the image, but a better solution is to use Picasso hope this helps!