2

I am getting an OutOfMemmory error while loading an image in an activity. I have one activity with one image and thats it. I dont understand how one image can cause this error

Log:

java.lang.OutOfMemoryError: Failed to allocate a 144288012 byte allocation with 2126212 free bytes and 92MB until OOM
                                                 at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                 at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                 at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620)
                                                 at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)
                                                 at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155)
                                                 at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720)
                                                 at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
                                                 at android.content.res.Resources.loadDrawable(Resources.java:858)
                                                 at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
                                                 at android.widget.ImageView.<init>(ImageView.java:162)
                                                 at android.widget.ImageView.<init>(ImageView.java:150)
                                                 at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
                                                 at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
                                                 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                 at in.snipped.snippedsalons.MainActivity.onCreate(MainActivity.kt:10)
                                                 at android.app.Activity.performCreate(Activity.java:6679)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                 at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                 at android.os.Looper.loop(Looper.java:154)
                                                 at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
5
  • What is the size of the image? Commented Jan 6, 2018 at 18:16
  • Its about 250kb Commented Jan 6, 2018 at 18:19
  • you need to check the size of the drawable you r choosing from resources or gallery. Commented Jan 6, 2018 at 18:19
  • Isnt 250kb small? Commented Jan 6, 2018 at 18:20
  • Possible duplicate of Android Outofmemory drawable Commented Jan 6, 2018 at 18:25

2 Answers 2

0

Please add the missing in manifest application

<application
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

You can find more here

Sign up to request clarification or add additional context in comments.

1 Comment

"Do not solve this kind of issue with android:largeHeap="true", that's not a solution".
0

There are two solution to get rid of this error

  1. Compress your image and change the resolution as per your need.
  2. Use glide to load image, glide make copy of that image as according to your image view's size

You can try both.

5 Comments

The image is just 250kb. That isn't that big
yes that's big , your image size should be 50 to 60 kb approx
and also this size increase app size which is not best practice
Yeah but this is the logo and I kinda need it here
then use glide to do your task

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.