0

I'm trying to run an app but I have no idea why it's not working. I'm getting this error in the first line in the console:

java.lang.OutOfMemoryError: Failed to allocate a 498534412 byte allocation with 4194304 free bytes and 331MB until OOM

After picking an USB connected Android or emulator, it says unfortunately, app has stopped.

I have no idea where to go from here.

Laurel
  • 5,965
  • 14
  • 31
  • 57
DkgMarine
  • 59
  • 6
  • Do you perhaps have images/bitmaps in your project? Also, could you try adding the `android:largeHeap="true"` in your Manifest's Application tag? Give that a try. You might also find [the discussion and the selected answer here helpful](http://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio) - seems closely related to your problem. – ishmaelMakitla Jun 05 '16 at 21:48
  • @ishmaelMakitla i have multiple ImageButtons actually. and i get the same error even after adding largeHeap to manifest – DkgMarine Jun 05 '16 at 21:52
  • @DkgMarine take care of the images on the buttons: if they're too large, they may cause the app to crash. Either make them smaller, or look into some libraries used for images, or separate loading them into different threads/ – Vucko Jun 05 '16 at 21:56
  • Possible duplicate of [How to load large images in Android and avoiding the out of memory error?](http://stackoverflow.com/questions/21392972/how-to-load-large-images-in-android-and-avoiding-the-out-of-memory-error) – Hitesh Sahu Jun 05 '16 at 23:59
  • Adding large heap in manifest is not a good solution.. If you are using `BitmapFactory.Options`.. Then add `options.inSampleSize = 2`.. You can check for the documentation [here](https://developer.android.com/training/displaying-bitmaps/load-bitmap.html) – Sanoop Surendran Jun 06 '16 at 02:08

2 Answers2

0

Look in your code and see if you have loaded a huge bitmap drawable in your first Activity

qichuan
  • 1,110
  • 7
  • 8
0

It happens when you try to load Bimaps inefficiently in your app .

You can do googling and get your hand dirty trying to figure out how to load bitmap efficiently or simply let Glide handle loading and caching of images.

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154