1
When there was only one drawable folder this error was not happening, only that the app was distorted in other resolutions, so I created the drawable folders with different resolutions(ldpi, hdpi...) and inside them I put the image I want to set with its due DPI in each. From this the application began to break at the time the image should be set. If I delete the drawable folders and let only the default works.
04-26 14:42:13.261 1467-1467/com.app.gustavo.jogodavelha E/dalvikvm-heap﹕ 78925456-byte external allocation too large for this process.
04-26 14:42:13.280 1467-1469/com.app.gustavo.jogodavelha D/dalvikvm﹕ GC_FOR_MALLOC freed 4K, 50% free 2837K/5639K, external 2755K/3376K, paused 4ms
04-26 14:42:13.280 1467-1467/com.app.gustavo.jogodavelha E/GraphicsJNI﹕ VM won't let us allocate 78925456 bytes
04-26 14:42:13.280 1467-1467/com.app.gustavo.jogodavelha D/skia﹕ --- decoder->decode returned false
04-26 14:42:13.280 1467-1467/com.app.gustavo.jogodavelha D/AndroidRuntime﹕ Shutting down VM
04-26 14:42:13.280 1467-1467/com.app.gustavo.jogodavelha W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3fe14f0)
04-26 14:42:13.280 1467-1467/com.app.gustavo.jogodavelha E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:2144)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2139)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.view.View.setBackgroundResource(View.java:7533)
at com.app.gustavo.jogodavelha.Main.clickQuadrado(Main.java:45)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2139)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Pole the log error and the code you are using to "set" the image.
– ramaral
I edited the question
– Ablon
This is the cause of the error:
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
. that in simple terms means that the image is too large, the memory is insufficient to treat this image.– ramaral
Minutes, but why when I leave only one drawable folder does not appear error?
– Ablon
I think it must be because the image in that folder is smaller.
– ramaral
From what I understood from the error log, when loading the image there was a 78MB allocation. One suggestion I give is to implement a cache algorithm using the
LRUCache
and add the image at a reasonable resolution, something around 800x600 and let theImageView
scale using thescaleType
or yourself while loading. Ah, another suggestion is to put the image in the folderdrawable-nodpi
.– Wakim
That was really the problem thanks.
– Ablon