0

Can anybody explain to me this LogCat output and how to solve it? I was testing my Android app with my cellphone (Samsung Galaxy Nexus) and just like that; the system forced detention and printed this in the LogCat...

04-17 09:43:09.189: E/AndroidRuntime(1194): FATAL EXCEPTION: main
04-17 09:43:09.189: E/AndroidRuntime(1194): java.lang.OutOfMemoryError
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:301)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:326)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.graphics.drawable.Drawable.createFromPath(Drawable.java:894)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.ImageView.resolveUri(ImageView.java:638)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.ImageView.setImageURI(ImageView.java:379)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at tian.proto.galeriaImagenes$ImageAdapter.getView(galeriaImagenes.java:169)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.Choreographer.doFrame(Choreographer.java:525)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.os.Handler.handleCallback(Handler.java:615)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.os.Looper.loop(Looper.java:137)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at android.app.ActivityThread.main(ActivityThread.java:4899)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at java.lang.reflect.Method.invokeNative(Native Method)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at java.lang.reflect.Method.invoke(Method.java:511)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
04-17 09:43:09.189: E/AndroidRuntime(1194):     at dalvik.system.NativeStart.main(Native Method)
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
alois.wirkes
  • 369
  • 2
  • 7
  • 20

2 Answers2

0

If you are loading the bitmap at runtime, you can scale it down as you read it from the device using this technique. If you're loading it from the res directory, you may just need to scale it down using an image editor. Either way, the image is apparently too large to fit in memory.

oakes
  • 743
  • 5
  • 12
0

As I see, you use ImageView.setImageURI to load the image.

Now many images, especially taken by higher resolution cameras (or phones) , images easily take up far more space than actually needed to display them on the screen.

When you try to directly load them into a Bitmap, your app will run out of memory and crash. Also see this question or the answer by @oakleaf for the link to the Android Developer Training about using large bitmaps.

Community
  • 1
  • 1
Patrick
  • 4,720
  • 4
  • 41
  • 71