1

i get sometime this error on my project. But why? Im really new in android programming can you help me? i dont know why i get this error.

12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime: FATAL EXCEPTION: main
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime: Process: com.cgame.angebotliste, PID: 32649
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 36000012 byte allocation with 16777120 free bytes and 28MB until OOM
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:741)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:562)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.content.res.Resources.loadDrawableForCookie(Resources.java:3702)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.content.res.Resources.loadDrawable(Resources.java:3575)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.content.res.Resources.getDrawable(Resources.java:1848)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.content.res.Resources.getDrawable(Resources.java:1814)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at com.squareup.picasso.RequestCreator.getPlaceholderDrawable(RequestCreator.java:676)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at com.squareup.picasso.RequestCreator.into(RequestCreator.java:664)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at com.cgame.angebotliste.BeichteShow_Adapter.loadImageFromUrl(BeichteShow_Adapter.java:199)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at com.cgame.angebotliste.BeichteShow_Adapter.onBindViewHolder(BeichteShow_Adapter.java:100)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at com.cgame.angebotliste.BeichteShow_Adapter.onBindViewHolder(BeichteShow_Adapter.java:42)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5217)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
12-14 16:45:18.172 32649-32649/com.cgame.angebotliste E/AndroidRuntime:     at 
Kevin V
  • 129
  • 2
  • 9
  • "But why?" -- because you are trying to allocate a very large block of memory (~35MB). You will not have that large of a block of memory on most devices. Your placeholder drawable is much too large and is probably in the wrong directory. – CommonsWare Dec 14 '15 at 15:58
  • The error comes when i make a http call in one intent and after this call switch very fast to a other intent with a recyleview. All my images have a size of ~50kb i have no image with over 34MB – Kevin V Dec 14 '15 at 16:54
  • "The error comes..." ...in all sorts of situations. You *happen* to be making it recur this way, but there will be others. "All my images have a size of ~50kb" -- presumably, you are referring to the size on disk. What matters is the decoded size in memory, which will be 10-30 times larger, plus any rescaling that is done due to different densities (resource compared to the device). – CommonsWare Dec 14 '15 at 17:10

3 Answers3

0

You are trying to load very large image:

BeichteShow_Adapter.loadImageFromUrl(BeichteShow_Adapter.java:199)

you should scale it down, there are lots of questions on SO for doing this ie:

OutOfMemory when loading large Background Image

Community
  • 1
  • 1
marcinj
  • 48,511
  • 9
  • 79
  • 100
0

I recommend to use Glide or Fresco for loading images. These libarries will automatically handle those edge cases for you.

sha
  • 1,410
  • 2
  • 18
  • 37
0

i had the same error and i fixed it by restarting the amulator. this solution doesnt work on every cases because in my case, another Project was running on amulator even i displayed another Project.

with some research i found that sometimes (i dont know why) map apps dont shut it down and still displaying on the phone or emulator.

maybe this helps.