Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and...












265















I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting OutOfMemoryError error of:




(java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM)




I have no idea or why its out of memory. I think my image size is very large so I tried to change it.



Iterator<String> it = imageArray.iterator();
while (it.hasNext()) {
Object element = it.next();
String objElement = element.toString();
Log.e("objElement ", " = " + objElement);
final ImageView imageView = new ImageView (getContext());
final ProgressBar pBar = new ProgressBar(getContext(), null,
android.R.attr.progressBarStyleSmall);
imageView.setTag(it);
pBar.setTag(it);

imageView.setImageResource(R.drawable.img_placeholder);
pBar.setVisibility(View.VISIBLE);

if (objElement.endsWith(mp3_Pattern)) {
Log.e("Mp3 ", " ends with ");
pBar.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.audio_control);
}
if (objElement.endsWith(png_Pattern)) {
Bitmap bitmap = BitmapFactory.decodeFile(objElement);
int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
int x = (bitmap.getWidth() - size) / 2;
int y = (bitmap.getHeight() - size) / 2;
Bitmap bitmap_Resul = Bitmap.createBitmap(bitmap, x, y, size, size);
Log.e("bitmap_Resul "," = "+ bitmap_Resul);

if (bitmap_Resul != bitmap) {
bitmap.recycle();
}
imageView.setImageBitmap(bitmap_Resul);
Log.e("png_Pattern ", " ends with ");
Log.e(" bitmap "," = " + bitmap);
}

holder.linearLayout.addView(imageView);
holder.linearLayout.addView(pBar);


The log cat information:



08-27 14:11:15.307    1857-1857/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tazeen.classnkk, PID: 1857
java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:789)
at android.graphics.Bitmap.createBitmap(Bitmap.java:709)
at android.graphics.Bitmap.createBitmap(Bitmap.java:634)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getView(AllPosts_Page.java:357)
at android.widget.AbsListView.obtainView(AbsListView.java:2347)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1659)
at android.widget.AbsListView.onLayout(AbsListView.java:2151)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)









share|improve this question




















  • 3





    check the pixels of the image, the width must not exceed 1440 and height 2560, by doing this it won't show OutOfMemoryError

    – Pankaj Lilan
    Dec 16 '16 at 9:28








  • 1





    @PankajLilan Where did you find these values (1440 X 2560)? Any references from android documentations?

    – Lijo
    Jul 14 '17 at 18:00











  • See also stackoverflow.com/questions/477572/…

    – JFreeman
    Feb 14 at 3:53


















265















I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting OutOfMemoryError error of:




(java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM)




I have no idea or why its out of memory. I think my image size is very large so I tried to change it.



Iterator<String> it = imageArray.iterator();
while (it.hasNext()) {
Object element = it.next();
String objElement = element.toString();
Log.e("objElement ", " = " + objElement);
final ImageView imageView = new ImageView (getContext());
final ProgressBar pBar = new ProgressBar(getContext(), null,
android.R.attr.progressBarStyleSmall);
imageView.setTag(it);
pBar.setTag(it);

imageView.setImageResource(R.drawable.img_placeholder);
pBar.setVisibility(View.VISIBLE);

if (objElement.endsWith(mp3_Pattern)) {
Log.e("Mp3 ", " ends with ");
pBar.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.audio_control);
}
if (objElement.endsWith(png_Pattern)) {
Bitmap bitmap = BitmapFactory.decodeFile(objElement);
int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
int x = (bitmap.getWidth() - size) / 2;
int y = (bitmap.getHeight() - size) / 2;
Bitmap bitmap_Resul = Bitmap.createBitmap(bitmap, x, y, size, size);
Log.e("bitmap_Resul "," = "+ bitmap_Resul);

if (bitmap_Resul != bitmap) {
bitmap.recycle();
}
imageView.setImageBitmap(bitmap_Resul);
Log.e("png_Pattern ", " ends with ");
Log.e(" bitmap "," = " + bitmap);
}

holder.linearLayout.addView(imageView);
holder.linearLayout.addView(pBar);


The log cat information:



08-27 14:11:15.307    1857-1857/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tazeen.classnkk, PID: 1857
java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:789)
at android.graphics.Bitmap.createBitmap(Bitmap.java:709)
at android.graphics.Bitmap.createBitmap(Bitmap.java:634)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getView(AllPosts_Page.java:357)
at android.widget.AbsListView.obtainView(AbsListView.java:2347)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1659)
at android.widget.AbsListView.onLayout(AbsListView.java:2151)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)









share|improve this question




















  • 3





    check the pixels of the image, the width must not exceed 1440 and height 2560, by doing this it won't show OutOfMemoryError

    – Pankaj Lilan
    Dec 16 '16 at 9:28








  • 1





    @PankajLilan Where did you find these values (1440 X 2560)? Any references from android documentations?

    – Lijo
    Jul 14 '17 at 18:00











  • See also stackoverflow.com/questions/477572/…

    – JFreeman
    Feb 14 at 3:53
















265












265








265


102






I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting OutOfMemoryError error of:




(java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM)




I have no idea or why its out of memory. I think my image size is very large so I tried to change it.



Iterator<String> it = imageArray.iterator();
while (it.hasNext()) {
Object element = it.next();
String objElement = element.toString();
Log.e("objElement ", " = " + objElement);
final ImageView imageView = new ImageView (getContext());
final ProgressBar pBar = new ProgressBar(getContext(), null,
android.R.attr.progressBarStyleSmall);
imageView.setTag(it);
pBar.setTag(it);

imageView.setImageResource(R.drawable.img_placeholder);
pBar.setVisibility(View.VISIBLE);

if (objElement.endsWith(mp3_Pattern)) {
Log.e("Mp3 ", " ends with ");
pBar.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.audio_control);
}
if (objElement.endsWith(png_Pattern)) {
Bitmap bitmap = BitmapFactory.decodeFile(objElement);
int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
int x = (bitmap.getWidth() - size) / 2;
int y = (bitmap.getHeight() - size) / 2;
Bitmap bitmap_Resul = Bitmap.createBitmap(bitmap, x, y, size, size);
Log.e("bitmap_Resul "," = "+ bitmap_Resul);

if (bitmap_Resul != bitmap) {
bitmap.recycle();
}
imageView.setImageBitmap(bitmap_Resul);
Log.e("png_Pattern ", " ends with ");
Log.e(" bitmap "," = " + bitmap);
}

holder.linearLayout.addView(imageView);
holder.linearLayout.addView(pBar);


The log cat information:



08-27 14:11:15.307    1857-1857/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tazeen.classnkk, PID: 1857
java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:789)
at android.graphics.Bitmap.createBitmap(Bitmap.java:709)
at android.graphics.Bitmap.createBitmap(Bitmap.java:634)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getView(AllPosts_Page.java:357)
at android.widget.AbsListView.obtainView(AbsListView.java:2347)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1659)
at android.widget.AbsListView.onLayout(AbsListView.java:2151)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)









share|improve this question
















I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting OutOfMemoryError error of:




(java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM)




I have no idea or why its out of memory. I think my image size is very large so I tried to change it.



Iterator<String> it = imageArray.iterator();
while (it.hasNext()) {
Object element = it.next();
String objElement = element.toString();
Log.e("objElement ", " = " + objElement);
final ImageView imageView = new ImageView (getContext());
final ProgressBar pBar = new ProgressBar(getContext(), null,
android.R.attr.progressBarStyleSmall);
imageView.setTag(it);
pBar.setTag(it);

imageView.setImageResource(R.drawable.img_placeholder);
pBar.setVisibility(View.VISIBLE);

if (objElement.endsWith(mp3_Pattern)) {
Log.e("Mp3 ", " ends with ");
pBar.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.audio_control);
}
if (objElement.endsWith(png_Pattern)) {
Bitmap bitmap = BitmapFactory.decodeFile(objElement);
int size = Math.min(bitmap.getWidth(), bitmap.getHeight());
int x = (bitmap.getWidth() - size) / 2;
int y = (bitmap.getHeight() - size) / 2;
Bitmap bitmap_Resul = Bitmap.createBitmap(bitmap, x, y, size, size);
Log.e("bitmap_Resul "," = "+ bitmap_Resul);

if (bitmap_Resul != bitmap) {
bitmap.recycle();
}
imageView.setImageBitmap(bitmap_Resul);
Log.e("png_Pattern ", " ends with ");
Log.e(" bitmap "," = " + bitmap);
}

holder.linearLayout.addView(imageView);
holder.linearLayout.addView(pBar);


The log cat information:



08-27 14:11:15.307    1857-1857/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tazeen.classnkk, PID: 1857
java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:789)
at android.graphics.Bitmap.createBitmap(Bitmap.java:709)
at android.graphics.Bitmap.createBitmap(Bitmap.java:634)
at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getView(AllPosts_Page.java:357)
at android.widget.AbsListView.obtainView(AbsListView.java:2347)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1659)
at android.widget.AbsListView.onLayout(AbsListView.java:2151)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)






android android-bitmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 3 '17 at 13:20









Cœur

18.7k9110150




18.7k9110150










asked Aug 27 '15 at 8:55









androidTagandroidTag

1,55661119




1,55661119








  • 3





    check the pixels of the image, the width must not exceed 1440 and height 2560, by doing this it won't show OutOfMemoryError

    – Pankaj Lilan
    Dec 16 '16 at 9:28








  • 1





    @PankajLilan Where did you find these values (1440 X 2560)? Any references from android documentations?

    – Lijo
    Jul 14 '17 at 18:00











  • See also stackoverflow.com/questions/477572/…

    – JFreeman
    Feb 14 at 3:53
















  • 3





    check the pixels of the image, the width must not exceed 1440 and height 2560, by doing this it won't show OutOfMemoryError

    – Pankaj Lilan
    Dec 16 '16 at 9:28








  • 1





    @PankajLilan Where did you find these values (1440 X 2560)? Any references from android documentations?

    – Lijo
    Jul 14 '17 at 18:00











  • See also stackoverflow.com/questions/477572/…

    – JFreeman
    Feb 14 at 3:53










3




3





check the pixels of the image, the width must not exceed 1440 and height 2560, by doing this it won't show OutOfMemoryError

– Pankaj Lilan
Dec 16 '16 at 9:28







check the pixels of the image, the width must not exceed 1440 and height 2560, by doing this it won't show OutOfMemoryError

– Pankaj Lilan
Dec 16 '16 at 9:28






1




1





@PankajLilan Where did you find these values (1440 X 2560)? Any references from android documentations?

– Lijo
Jul 14 '17 at 18:00





@PankajLilan Where did you find these values (1440 X 2560)? Any references from android documentations?

– Lijo
Jul 14 '17 at 18:00













See also stackoverflow.com/questions/477572/…

– JFreeman
Feb 14 at 3:53







See also stackoverflow.com/questions/477572/…

– JFreeman
Feb 14 at 3:53














26 Answers
26






active

oldest

votes


















399














OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.



As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.



<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 should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently



Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.



Here some of possible answers for these type of errors in SOF



Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap



How to solve java.lang.OutOfMemoryError trouble in Android



Android : java.lang.OutOfMemoryError



java.lang.OutOfMemoryError



Solution for OutOfMemoryError: bitmap size exceeds VM budget



Edit: From the comments of @cjnash



For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.






share|improve this answer





















  • 1





    Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

    – Aleksey Timoshchenko
    Apr 20 '16 at 6:37






  • 3





    app navigation is becoming very slow after adding this.

    – Uma Achanta
    Dec 30 '16 at 7:47






  • 4





    android:hardwareAccelerated="false" freezing your app

    – Rahim Rahimov
    Apr 15 '17 at 15:00






  • 1





    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

    – cjnash
    Aug 1 '17 at 15:45






  • 2





    why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

    – batmaci
    Dec 13 '17 at 16:04



















76














have you tried adding this to your manifest under applications? android:largeHeap="true"?



like this



  <application
android:name=".ParaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:largeHeap="true" >





share|improve this answer





















  • 10





    I have tried with this android:largeHeap="true" but getting same error

    – androidTag
    Aug 27 '15 at 9:42






  • 1





    try compressing your image before you can use this link to do so tinyjpg.com

    – TSG
    Aug 27 '15 at 11:22








  • 1





    you can also compress png with this site

    – TSG
    Aug 27 '15 at 11:23



















25














Actually you can add in your manifest these lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware that the other part of code can be arguing with this.



<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">





share|improve this answer





















  • 2





    didn't work, it crashed with the same error, when used Bitmap.createBitmap

    – NarendraJi
    Sep 14 '16 at 7:51











  • @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

    – Aleksey Timoshchenko
    Sep 28 '16 at 8:19











  • @MrNarendra how didi you solve it then?

    – Shruti
    Jul 19 '17 at 5:27











  • What is the purpose of android:hardwareAccelerated="false"?

    – IgorGanapolsky
    Oct 13 '17 at 15:05











  • @IgorGanapolsky From official doc says.. see this link

    – Shylendra Madda
    Oct 23 '17 at 5:40





















19














For me, the problem was that my .png file was being de-compressed to be a really huge bitmap in memory, because the image had very large dimensions (even though the file size was tiny).



So the fix was to simply resize the image :)






share|improve this answer



















  • 1





    this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

    – Kaushal28
    May 29 '17 at 5:29






  • 1





    this fixed my problem. Thank you @petrus

    – Hùng Nguyễn
    Sep 10 '17 at 4:12



















16














This should work



 BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;

mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);





share|improve this answer
























  • This answer is solved my problem.

    – Thirumalvalavan
    Jan 29 '18 at 13:13





















8














Use Glide Library and Override size to less size;



Glide.with(mContext).load(imgID).asBitmap().override(1080, 600).into(mImageView);





share|improve this answer

































    8














    Resize your image before setup to ImageView like this:



    Bitmap.createScaledBitmap(_yourImageBitmap, _size, _size, false);


    where size is actual size of ImageView. You can reach size by measuring:



    imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));


    and use next size imageView.getMeasuredWidth() and imageView.getMeasuredHeight() for scaling.






    share|improve this answer


























    • I have tried with this android:largeHeap="true" but getting same error

      – androidTag
      Aug 27 '15 at 9:46











    • A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

      – CmosBattery
      Apr 22 '16 at 13:59



















    4














    I have resolved this problem by resizing the image to lower size. I am using xamarin form. decreasing the size of the PNG image resolved the problem.






    share|improve this answer































      3














      I got below error




      "E/art: Throwing OutOfMemoryError "Failed to allocate a 47251468 byte
      allocation with 16777120 free bytes and 23MB until OOM"




      after adding android:largeHeap="true" in AndroidManifest.xml then I rid of all the errors



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





      share|improve this answer





















      • 2





        Didn't work for my case

        – Sami Eltamawy
        Nov 27 '16 at 12:05



















      3














      Soluton try this in your Manifest File and use Glide Library



      compile 'com.github.bumptech.glide:glide:3.7.0'



          **Use Glide Library and Override size to less size;**

      if (!TextUtils.isEmpty(message.getPicture())) {
      Glide.with(mContext).load(message.getPicture())
      .thumbnail(0.5f)
      .crossFade()
      .transform(new CircleTransform(mContext))
      .diskCacheStrategy(DiskCacheStrategy.ALL)
      .into(holder.imgProfile);
      }


      android:hardwareAccelerated="false"



      android:largeHeap="true"



      <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">


      Use this library



        compile 'com.github.bumptech.glide:glide:3.7.0'   


      Its Working Happy Coding



      import android.content.Context;
      import android.graphics.Bitmap;
      import android.graphics.BitmapShader;
      import android.graphics.Canvas;
      import android.graphics.Paint;

      import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
      import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;


      public class CircleTransform extends BitmapTransformation {
      public CircleTransform(Context context) {
      super(context);
      }

      @Override
      protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
      return circleCrop(pool, toTransform);
      }

      private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
      if (source == null) return null;

      int size = Math.min(source.getWidth(), source.getHeight());
      int x = (source.getWidth() - size) / 2;
      int y = (source.getHeight() - size) / 2;

      // TODO this could be acquired from the pool too
      Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

      Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
      if (result == null) {
      result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
      }

      Canvas canvas = new Canvas(result);
      Paint paint = new Paint();
      paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
      paint.setAntiAlias(true);
      float r = size / 2f;
      canvas.drawCircle(r, r, r, paint);
      return result;
      }

      @Override
      public String getId() {
      return getClass().getName();
      }
      }





      share|improve this answer

































        3















        Issue : Failed to allocate a 37748748 byte allocation with 16777120
        free bytes and 17MB until OOM




        Solution :
        1.open your manifest file
        2. inside application tag just add below two lines



         android:hardwareAccelerated="false"
        android:largeHeap="true"


        Example :



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





        share|improve this answer

































          2














          I had the problem too.



          Same with most of others above.
          The problem is caused by huge image.



          Just resize some images,
          and no need to change any code.






          share|improve this answer































            1














            I'm a newbie in android developing but I hope my solution helps, it works on my condition perfectly. Im using Imageview and set it's background to "src" because im trying to make a frame animation. I got the same error but when I tried to code this it worked



            int ImageID = this.Resources.GetIdentifier(questionPlay[index].Image.ToLower(), "anim", PackageName);
            imgView.SetImageResource(ImageID);
            AnimationDrawable animation = (AnimationDrawable)imgView.Drawable;
            animation.Start();
            animation.Dispose();





            share|improve this answer































              1














              In some cases (e.g. operations in a loop) garbage collector is slower than your code. You can use a helper method from this answer to wait for garbage collector.






              share|improve this answer































                1














                I ran into this problem when I didn't kill off my old activity when moving on to a new activity. I fixed it with finish();



                    Intent goToMain = new Intent(this,MainActivity.class);
                startActivity(goToMain);
                finish();





                share|improve this answer































                  1














                  This worked for me: just move images from drawable folder to drawable-hdpi.






                  share|improve this answer
























                  • what the explanation of this? why this moving works ?

                    – Harun
                    Apr 19 '18 at 5:04



















                  1














                  Bitmap image =((BitmapDrawable)imageView1.getDrawable()).getBitmap();

                  ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();

                  image.compress(Bitmap.CompressFormat.JPEG,50/100,byteArrayOutputStream);


                  50/100 if one uses 100 then original resolution can stopped the Apps for out of memory.



                  if 50 or less than 100 this will be 50% or less than 100 resolution so this will prevent from out of memory problem






                  share|improve this answer

































                    1














                    I have found that images in the 'drawable' folder will get converted to a much larger image on high def phones. For example, a 200k image will be resampled to a higher res, like 800k or 32000k. I had to discover this on my own and to date have not seen documentation for this heap memory trap. To prevent this I put everything in a drawable-nodpi folder (in addition to using 'options' in BitmapFactory based on the particular device heap). I can't afford to have the size of my app bloated with multiple drawable folders, particularly as the range of screen defs is so vast now. The tricky thing is studio now doesn't specifically indicate the 'drawable-nodpi' folder as such in the project view, it just shows a 'drawable' folder. If you're not careful, when you drop an image to this folder in studio, it won't actually get dropped into the drawable-nodpi:



                    Careful here 'backgroundtest' did not actually go to drawable-nodpi and will 
                    be resampled higher, such as 4x or 16x of the original dimensions for high def screens.


                    enter image description here



                    Be sure to click down to the nodpi folder in the dialogue, as the project view won't show you all drawable folders separately like it used to, so it won't be immediately apparent that it went to wrong one. Studio recreated the vanilla 'drawable' at some point for me after I had deleted it long ago:



                    enter image description here






                    share|improve this answer

































                      1














                      You have to change the size of object in drawable. It's too big for android to display. e.g. If you are setting image try image with less pixels. It works for me.
                      Thanks. :)






                      share|improve this answer































                        1














                        Your app is crashing because your image size (in MB Or KB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size.



                        OR



                        You can add Following in application tag at Manifest.xml



                         android:hardwareAccelerated="false"
                        android:largeHeap="true"
                        android:allowBackup="true"


                        After Adding this App will not Crash.




                        • always use less sizes images in App.

                        • If You adding large sizes of images in app , you should add above syntex, but App size will increase.






                        share|improve this answer































                          1














                          My problem solved after adding



                           dexOptions {
                          incremental true
                          javaMaxHeapSize "4g"
                          preDexLibraries true
                          dexInProcess = true
                          }


                          in Build.Gradle file






                          share|improve this answer
























                          • This just makes your app really bloated in memory usage

                            – cricket_007
                            Oct 27 '18 at 18:14



















                          0














                          If uploading an image, try reducing the image quality, which is the second parameter of the Bitmap. This was the solution in my case. Previously it was 90, then I tried with 60 (as it is in the code below now).



                          Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
                          ByteArrayOutputStream baos = new ByteArrayOutputStream();
                          finalBitmap.compress(Bitmap.CompressFormat.JPEG,60,baos);
                          byte b = baos.toByteArray();





                          share|improve this answer































                            0














                            Try the simplest one. Maybe Your app is crashing because your image size (in MB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size by any viewer software or if you are taking image from gallery at the run time than before saving it compress your bitmap.
                            It worked for me. definitely for u will be.






                            share|improve this answer

































                              0














                              stream = activity.getContentResolver().openInputStream(uri);
                              BitmapFactory.Options options = new BitmapFactory.Options();
                              options.inPreferredConfig = Bitmap.Config.RGB_565;

                              bitmap = BitmapFactory.decodeStream(stream, null, options);
                              int Height = bitmap.getHeight();
                              int Width = bitmap.getWidth();
                              enter code here
                              int newHeight = 1000;
                              float scaleFactor = ((float) newHeight) / Height;
                              float newWidth = Width * scaleFactor;

                              float scaleWidth = scaleFactor;
                              float scaleHeight = scaleFactor;
                              Matrix matrix = new Matrix();
                              matrix.postScale(scaleWidth, scaleHeight);
                              resizedBitmap= Bitmap.createBitmap(bitmap, 0, 0,Width, Height, matrix, true);
                              bitmap.recycle();


                              Then in Appliaction tag, add largeheapsize="true






                              share|improve this answer

































                                0














                                Last but not the least....

                                Try Method One:

                                Simple Add these lines of code in the gradle file

                                dexOptions {
                                incremental true
                                javaMaxHeapSize "4g"
                                }

                                Example:

                                android {
                                compileSdkVersion XX
                                buildToolsVersion "28.X.X"

                                defaultConfig {
                                applicationId "com.example.xxxxx"
                                minSdkVersion 14
                                targetSdkVersion 19
                                }

                                dexOptions {
                                incremental true
                                javaMaxHeapSize "4g"
                                }
                                }

                                *******************************************************************

                                Method Two:

                                Add these two lines of code in manifest file...

                                android:hardwareAccelerated="false"
                                android:largeHeap="true"

                                Example:

                                <application
                                android:allowBackup="true"
                                android:icon="@drawable/ic_launcher"
                                android:hardwareAccelerated="false"
                                android:largeHeap="true"
                                android:label="@string/app_name"
                                android:theme="@style/AppTheme" >
                                <activity
                                android:name=".MainActivity"
                                android:label="@string/app_name" >
                                <intent-filter>
                                <action android:name="android.intent.action.MAIN" />

                                <category android:name="android.intent.category.LAUNCHER" />
                                </intent-filter>
                                </activity>
                                </application>

                                It will Work for sure any of these cases.....





                                share|improve this answer































                                  0














                                  Use an image loading library like Picasso or Glide. Using these libraries will prevent crashes in the future.






                                  share|improve this answer






















                                    protected by Community Aug 26 '17 at 0:17



                                    Thank you for your interest in this question.
                                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                    Would you like to answer one of these unanswered questions instead?














                                    26 Answers
                                    26






                                    active

                                    oldest

                                    votes








                                    26 Answers
                                    26






                                    active

                                    oldest

                                    votes









                                    active

                                    oldest

                                    votes






                                    active

                                    oldest

                                    votes









                                    399














                                    OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.



                                    As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.



                                    <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 should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently



                                    Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.



                                    Here some of possible answers for these type of errors in SOF



                                    Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap



                                    How to solve java.lang.OutOfMemoryError trouble in Android



                                    Android : java.lang.OutOfMemoryError



                                    java.lang.OutOfMemoryError



                                    Solution for OutOfMemoryError: bitmap size exceeds VM budget



                                    Edit: From the comments of @cjnash



                                    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.






                                    share|improve this answer





















                                    • 1





                                      Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

                                      – Aleksey Timoshchenko
                                      Apr 20 '16 at 6:37






                                    • 3





                                      app navigation is becoming very slow after adding this.

                                      – Uma Achanta
                                      Dec 30 '16 at 7:47






                                    • 4





                                      android:hardwareAccelerated="false" freezing your app

                                      – Rahim Rahimov
                                      Apr 15 '17 at 15:00






                                    • 1





                                      For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

                                      – cjnash
                                      Aug 1 '17 at 15:45






                                    • 2





                                      why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

                                      – batmaci
                                      Dec 13 '17 at 16:04
















                                    399














                                    OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.



                                    As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.



                                    <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 should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently



                                    Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.



                                    Here some of possible answers for these type of errors in SOF



                                    Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap



                                    How to solve java.lang.OutOfMemoryError trouble in Android



                                    Android : java.lang.OutOfMemoryError



                                    java.lang.OutOfMemoryError



                                    Solution for OutOfMemoryError: bitmap size exceeds VM budget



                                    Edit: From the comments of @cjnash



                                    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.






                                    share|improve this answer





















                                    • 1





                                      Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

                                      – Aleksey Timoshchenko
                                      Apr 20 '16 at 6:37






                                    • 3





                                      app navigation is becoming very slow after adding this.

                                      – Uma Achanta
                                      Dec 30 '16 at 7:47






                                    • 4





                                      android:hardwareAccelerated="false" freezing your app

                                      – Rahim Rahimov
                                      Apr 15 '17 at 15:00






                                    • 1





                                      For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

                                      – cjnash
                                      Aug 1 '17 at 15:45






                                    • 2





                                      why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

                                      – batmaci
                                      Dec 13 '17 at 16:04














                                    399












                                    399








                                    399







                                    OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.



                                    As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.



                                    <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 should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently



                                    Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.



                                    Here some of possible answers for these type of errors in SOF



                                    Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap



                                    How to solve java.lang.OutOfMemoryError trouble in Android



                                    Android : java.lang.OutOfMemoryError



                                    java.lang.OutOfMemoryError



                                    Solution for OutOfMemoryError: bitmap size exceeds VM budget



                                    Edit: From the comments of @cjnash



                                    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.






                                    share|improve this answer















                                    OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.



                                    As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.



                                    <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 should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently



                                    Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.



                                    Here some of possible answers for these type of errors in SOF



                                    Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap



                                    How to solve java.lang.OutOfMemoryError trouble in Android



                                    Android : java.lang.OutOfMemoryError



                                    java.lang.OutOfMemoryError



                                    Solution for OutOfMemoryError: bitmap size exceeds VM budget



                                    Edit: From the comments of @cjnash



                                    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Sep 20 '17 at 3:57

























                                    answered Aug 27 '15 at 9:02









                                    King of MassesKing of Masses

                                    12.6k44766




                                    12.6k44766








                                    • 1





                                      Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

                                      – Aleksey Timoshchenko
                                      Apr 20 '16 at 6:37






                                    • 3





                                      app navigation is becoming very slow after adding this.

                                      – Uma Achanta
                                      Dec 30 '16 at 7:47






                                    • 4





                                      android:hardwareAccelerated="false" freezing your app

                                      – Rahim Rahimov
                                      Apr 15 '17 at 15:00






                                    • 1





                                      For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

                                      – cjnash
                                      Aug 1 '17 at 15:45






                                    • 2





                                      why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

                                      – batmaci
                                      Dec 13 '17 at 16:04














                                    • 1





                                      Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

                                      – Aleksey Timoshchenko
                                      Apr 20 '16 at 6:37






                                    • 3





                                      app navigation is becoming very slow after adding this.

                                      – Uma Achanta
                                      Dec 30 '16 at 7:47






                                    • 4





                                      android:hardwareAccelerated="false" freezing your app

                                      – Rahim Rahimov
                                      Apr 15 '17 at 15:00






                                    • 1





                                      For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

                                      – cjnash
                                      Aug 1 '17 at 15:45






                                    • 2





                                      why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

                                      – batmaci
                                      Dec 13 '17 at 16:04








                                    1




                                    1





                                    Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

                                    – Aleksey Timoshchenko
                                    Apr 20 '16 at 6:37





                                    Could you please post how you eventually solved the issue? Because i have the same problem... Actually you can add in your manifest this lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware the that another part of code can be arguing with this...

                                    – Aleksey Timoshchenko
                                    Apr 20 '16 at 6:37




                                    3




                                    3





                                    app navigation is becoming very slow after adding this.

                                    – Uma Achanta
                                    Dec 30 '16 at 7:47





                                    app navigation is becoming very slow after adding this.

                                    – Uma Achanta
                                    Dec 30 '16 at 7:47




                                    4




                                    4





                                    android:hardwareAccelerated="false" freezing your app

                                    – Rahim Rahimov
                                    Apr 15 '17 at 15:00





                                    android:hardwareAccelerated="false" freezing your app

                                    – Rahim Rahimov
                                    Apr 15 '17 at 15:00




                                    1




                                    1





                                    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

                                    – cjnash
                                    Aug 1 '17 at 15:45





                                    For anyone that still had crashes after they added this line, try sticking your image into your res/drawable-xhdpi/ folder instead of your res/drawable/ and it might resolve your issue.

                                    – cjnash
                                    Aug 1 '17 at 15:45




                                    2




                                    2





                                    why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

                                    – batmaci
                                    Dec 13 '17 at 16:04





                                    why would you suggest android:hardwareAccelerated="false ? what is the benefit of it?

                                    – batmaci
                                    Dec 13 '17 at 16:04













                                    76














                                    have you tried adding this to your manifest under applications? android:largeHeap="true"?



                                    like this



                                      <application
                                    android:name=".ParaseApplication"
                                    android:allowBackup="true"
                                    android:icon="@mipmap/ic_launcher"
                                    android:label="@string/app_name"
                                    android:theme="@style/AppTheme"
                                    android:largeHeap="true" >





                                    share|improve this answer





















                                    • 10





                                      I have tried with this android:largeHeap="true" but getting same error

                                      – androidTag
                                      Aug 27 '15 at 9:42






                                    • 1





                                      try compressing your image before you can use this link to do so tinyjpg.com

                                      – TSG
                                      Aug 27 '15 at 11:22








                                    • 1





                                      you can also compress png with this site

                                      – TSG
                                      Aug 27 '15 at 11:23
















                                    76














                                    have you tried adding this to your manifest under applications? android:largeHeap="true"?



                                    like this



                                      <application
                                    android:name=".ParaseApplication"
                                    android:allowBackup="true"
                                    android:icon="@mipmap/ic_launcher"
                                    android:label="@string/app_name"
                                    android:theme="@style/AppTheme"
                                    android:largeHeap="true" >





                                    share|improve this answer





















                                    • 10





                                      I have tried with this android:largeHeap="true" but getting same error

                                      – androidTag
                                      Aug 27 '15 at 9:42






                                    • 1





                                      try compressing your image before you can use this link to do so tinyjpg.com

                                      – TSG
                                      Aug 27 '15 at 11:22








                                    • 1





                                      you can also compress png with this site

                                      – TSG
                                      Aug 27 '15 at 11:23














                                    76












                                    76








                                    76







                                    have you tried adding this to your manifest under applications? android:largeHeap="true"?



                                    like this



                                      <application
                                    android:name=".ParaseApplication"
                                    android:allowBackup="true"
                                    android:icon="@mipmap/ic_launcher"
                                    android:label="@string/app_name"
                                    android:theme="@style/AppTheme"
                                    android:largeHeap="true" >





                                    share|improve this answer















                                    have you tried adding this to your manifest under applications? android:largeHeap="true"?



                                    like this



                                      <application
                                    android:name=".ParaseApplication"
                                    android:allowBackup="true"
                                    android:icon="@mipmap/ic_launcher"
                                    android:label="@string/app_name"
                                    android:theme="@style/AppTheme"
                                    android:largeHeap="true" >






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 19 '16 at 6:47









                                    V-rund Puro-hit

                                    4,04682046




                                    4,04682046










                                    answered Aug 27 '15 at 9:02









                                    TSGTSG

                                    78148




                                    78148








                                    • 10





                                      I have tried with this android:largeHeap="true" but getting same error

                                      – androidTag
                                      Aug 27 '15 at 9:42






                                    • 1





                                      try compressing your image before you can use this link to do so tinyjpg.com

                                      – TSG
                                      Aug 27 '15 at 11:22








                                    • 1





                                      you can also compress png with this site

                                      – TSG
                                      Aug 27 '15 at 11:23














                                    • 10





                                      I have tried with this android:largeHeap="true" but getting same error

                                      – androidTag
                                      Aug 27 '15 at 9:42






                                    • 1





                                      try compressing your image before you can use this link to do so tinyjpg.com

                                      – TSG
                                      Aug 27 '15 at 11:22








                                    • 1





                                      you can also compress png with this site

                                      – TSG
                                      Aug 27 '15 at 11:23








                                    10




                                    10





                                    I have tried with this android:largeHeap="true" but getting same error

                                    – androidTag
                                    Aug 27 '15 at 9:42





                                    I have tried with this android:largeHeap="true" but getting same error

                                    – androidTag
                                    Aug 27 '15 at 9:42




                                    1




                                    1





                                    try compressing your image before you can use this link to do so tinyjpg.com

                                    – TSG
                                    Aug 27 '15 at 11:22







                                    try compressing your image before you can use this link to do so tinyjpg.com

                                    – TSG
                                    Aug 27 '15 at 11:22






                                    1




                                    1





                                    you can also compress png with this site

                                    – TSG
                                    Aug 27 '15 at 11:23





                                    you can also compress png with this site

                                    – TSG
                                    Aug 27 '15 at 11:23











                                    25














                                    Actually you can add in your manifest these lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware that the other part of code can be arguing with this.



                                    <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">





                                    share|improve this answer





















                                    • 2





                                      didn't work, it crashed with the same error, when used Bitmap.createBitmap

                                      – NarendraJi
                                      Sep 14 '16 at 7:51











                                    • @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

                                      – Aleksey Timoshchenko
                                      Sep 28 '16 at 8:19











                                    • @MrNarendra how didi you solve it then?

                                      – Shruti
                                      Jul 19 '17 at 5:27











                                    • What is the purpose of android:hardwareAccelerated="false"?

                                      – IgorGanapolsky
                                      Oct 13 '17 at 15:05











                                    • @IgorGanapolsky From official doc says.. see this link

                                      – Shylendra Madda
                                      Oct 23 '17 at 5:40


















                                    25














                                    Actually you can add in your manifest these lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware that the other part of code can be arguing with this.



                                    <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">





                                    share|improve this answer





















                                    • 2





                                      didn't work, it crashed with the same error, when used Bitmap.createBitmap

                                      – NarendraJi
                                      Sep 14 '16 at 7:51











                                    • @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

                                      – Aleksey Timoshchenko
                                      Sep 28 '16 at 8:19











                                    • @MrNarendra how didi you solve it then?

                                      – Shruti
                                      Jul 19 '17 at 5:27











                                    • What is the purpose of android:hardwareAccelerated="false"?

                                      – IgorGanapolsky
                                      Oct 13 '17 at 15:05











                                    • @IgorGanapolsky From official doc says.. see this link

                                      – Shylendra Madda
                                      Oct 23 '17 at 5:40
















                                    25












                                    25








                                    25







                                    Actually you can add in your manifest these lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware that the other part of code can be arguing with this.



                                    <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">





                                    share|improve this answer















                                    Actually you can add in your manifest these lines android:hardwareAccelerated="false" , android:largeHeap="true" it is working for some situations, but be aware that the other part of code can be arguing with this.



                                    <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">






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Oct 3 '16 at 5:49









                                    onexf

                                    1,71711530




                                    1,71711530










                                    answered Apr 20 '16 at 6:38









                                    Aleksey TimoshchenkoAleksey Timoshchenko

                                    1,2231837




                                    1,2231837








                                    • 2





                                      didn't work, it crashed with the same error, when used Bitmap.createBitmap

                                      – NarendraJi
                                      Sep 14 '16 at 7:51











                                    • @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

                                      – Aleksey Timoshchenko
                                      Sep 28 '16 at 8:19











                                    • @MrNarendra how didi you solve it then?

                                      – Shruti
                                      Jul 19 '17 at 5:27











                                    • What is the purpose of android:hardwareAccelerated="false"?

                                      – IgorGanapolsky
                                      Oct 13 '17 at 15:05











                                    • @IgorGanapolsky From official doc says.. see this link

                                      – Shylendra Madda
                                      Oct 23 '17 at 5:40
















                                    • 2





                                      didn't work, it crashed with the same error, when used Bitmap.createBitmap

                                      – NarendraJi
                                      Sep 14 '16 at 7:51











                                    • @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

                                      – Aleksey Timoshchenko
                                      Sep 28 '16 at 8:19











                                    • @MrNarendra how didi you solve it then?

                                      – Shruti
                                      Jul 19 '17 at 5:27











                                    • What is the purpose of android:hardwareAccelerated="false"?

                                      – IgorGanapolsky
                                      Oct 13 '17 at 15:05











                                    • @IgorGanapolsky From official doc says.. see this link

                                      – Shylendra Madda
                                      Oct 23 '17 at 5:40










                                    2




                                    2





                                    didn't work, it crashed with the same error, when used Bitmap.createBitmap

                                    – NarendraJi
                                    Sep 14 '16 at 7:51





                                    didn't work, it crashed with the same error, when used Bitmap.createBitmap

                                    – NarendraJi
                                    Sep 14 '16 at 7:51













                                    @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

                                    – Aleksey Timoshchenko
                                    Sep 28 '16 at 8:19





                                    @King sorry( i also spent some time in order to solve this issue, and it is work for me. But it is just one of the way... There are a lot of different approach

                                    – Aleksey Timoshchenko
                                    Sep 28 '16 at 8:19













                                    @MrNarendra how didi you solve it then?

                                    – Shruti
                                    Jul 19 '17 at 5:27





                                    @MrNarendra how didi you solve it then?

                                    – Shruti
                                    Jul 19 '17 at 5:27













                                    What is the purpose of android:hardwareAccelerated="false"?

                                    – IgorGanapolsky
                                    Oct 13 '17 at 15:05





                                    What is the purpose of android:hardwareAccelerated="false"?

                                    – IgorGanapolsky
                                    Oct 13 '17 at 15:05













                                    @IgorGanapolsky From official doc says.. see this link

                                    – Shylendra Madda
                                    Oct 23 '17 at 5:40







                                    @IgorGanapolsky From official doc says.. see this link

                                    – Shylendra Madda
                                    Oct 23 '17 at 5:40













                                    19














                                    For me, the problem was that my .png file was being de-compressed to be a really huge bitmap in memory, because the image had very large dimensions (even though the file size was tiny).



                                    So the fix was to simply resize the image :)






                                    share|improve this answer



















                                    • 1





                                      this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

                                      – Kaushal28
                                      May 29 '17 at 5:29






                                    • 1





                                      this fixed my problem. Thank you @petrus

                                      – Hùng Nguyễn
                                      Sep 10 '17 at 4:12
















                                    19














                                    For me, the problem was that my .png file was being de-compressed to be a really huge bitmap in memory, because the image had very large dimensions (even though the file size was tiny).



                                    So the fix was to simply resize the image :)






                                    share|improve this answer



















                                    • 1





                                      this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

                                      – Kaushal28
                                      May 29 '17 at 5:29






                                    • 1





                                      this fixed my problem. Thank you @petrus

                                      – Hùng Nguyễn
                                      Sep 10 '17 at 4:12














                                    19












                                    19








                                    19







                                    For me, the problem was that my .png file was being de-compressed to be a really huge bitmap in memory, because the image had very large dimensions (even though the file size was tiny).



                                    So the fix was to simply resize the image :)






                                    share|improve this answer













                                    For me, the problem was that my .png file was being de-compressed to be a really huge bitmap in memory, because the image had very large dimensions (even though the file size was tiny).



                                    So the fix was to simply resize the image :)







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Feb 6 '16 at 14:19









                                    petrus-jvrensburgpetrus-jvrensburg

                                    637714




                                    637714








                                    • 1





                                      this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

                                      – Kaushal28
                                      May 29 '17 at 5:29






                                    • 1





                                      this fixed my problem. Thank you @petrus

                                      – Hùng Nguyễn
                                      Sep 10 '17 at 4:12














                                    • 1





                                      this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

                                      – Kaushal28
                                      May 29 '17 at 5:29






                                    • 1





                                      this fixed my problem. Thank you @petrus

                                      – Hùng Nguyễn
                                      Sep 10 '17 at 4:12








                                    1




                                    1





                                    this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

                                    – Kaushal28
                                    May 29 '17 at 5:29





                                    this is the correct solution, because I firstly tried above solutions, but after applying android:hardwareAccelerated="false", some animations like layout shadow were not working. But after resizing all the problems were solved thank you! +1 for this hint!

                                    – Kaushal28
                                    May 29 '17 at 5:29




                                    1




                                    1





                                    this fixed my problem. Thank you @petrus

                                    – Hùng Nguyễn
                                    Sep 10 '17 at 4:12





                                    this fixed my problem. Thank you @petrus

                                    – Hùng Nguyễn
                                    Sep 10 '17 at 4:12











                                    16














                                    This should work



                                     BitmapFactory.Options options = new BitmapFactory.Options();
                                    options.inSampleSize = 8;

                                    mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);





                                    share|improve this answer
























                                    • This answer is solved my problem.

                                      – Thirumalvalavan
                                      Jan 29 '18 at 13:13


















                                    16














                                    This should work



                                     BitmapFactory.Options options = new BitmapFactory.Options();
                                    options.inSampleSize = 8;

                                    mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);





                                    share|improve this answer
























                                    • This answer is solved my problem.

                                      – Thirumalvalavan
                                      Jan 29 '18 at 13:13
















                                    16












                                    16








                                    16







                                    This should work



                                     BitmapFactory.Options options = new BitmapFactory.Options();
                                    options.inSampleSize = 8;

                                    mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);





                                    share|improve this answer













                                    This should work



                                     BitmapFactory.Options options = new BitmapFactory.Options();
                                    options.inSampleSize = 8;

                                    mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jul 25 '16 at 8:38









                                    Akshay komarlaAkshay komarla

                                    466815




                                    466815













                                    • This answer is solved my problem.

                                      – Thirumalvalavan
                                      Jan 29 '18 at 13:13





















                                    • This answer is solved my problem.

                                      – Thirumalvalavan
                                      Jan 29 '18 at 13:13



















                                    This answer is solved my problem.

                                    – Thirumalvalavan
                                    Jan 29 '18 at 13:13







                                    This answer is solved my problem.

                                    – Thirumalvalavan
                                    Jan 29 '18 at 13:13













                                    8














                                    Use Glide Library and Override size to less size;



                                    Glide.with(mContext).load(imgID).asBitmap().override(1080, 600).into(mImageView);





                                    share|improve this answer






























                                      8














                                      Use Glide Library and Override size to less size;



                                      Glide.with(mContext).load(imgID).asBitmap().override(1080, 600).into(mImageView);





                                      share|improve this answer




























                                        8












                                        8








                                        8







                                        Use Glide Library and Override size to less size;



                                        Glide.with(mContext).load(imgID).asBitmap().override(1080, 600).into(mImageView);





                                        share|improve this answer















                                        Use Glide Library and Override size to less size;



                                        Glide.with(mContext).load(imgID).asBitmap().override(1080, 600).into(mImageView);






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jan 20 '17 at 20:16









                                        Vinoth Vino

                                        3,20832739




                                        3,20832739










                                        answered Feb 16 '16 at 8:16









                                        Mahdi AzadbarMahdi Azadbar

                                        603718




                                        603718























                                            8














                                            Resize your image before setup to ImageView like this:



                                            Bitmap.createScaledBitmap(_yourImageBitmap, _size, _size, false);


                                            where size is actual size of ImageView. You can reach size by measuring:



                                            imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));


                                            and use next size imageView.getMeasuredWidth() and imageView.getMeasuredHeight() for scaling.






                                            share|improve this answer


























                                            • I have tried with this android:largeHeap="true" but getting same error

                                              – androidTag
                                              Aug 27 '15 at 9:46











                                            • A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

                                              – CmosBattery
                                              Apr 22 '16 at 13:59
















                                            8














                                            Resize your image before setup to ImageView like this:



                                            Bitmap.createScaledBitmap(_yourImageBitmap, _size, _size, false);


                                            where size is actual size of ImageView. You can reach size by measuring:



                                            imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));


                                            and use next size imageView.getMeasuredWidth() and imageView.getMeasuredHeight() for scaling.






                                            share|improve this answer


























                                            • I have tried with this android:largeHeap="true" but getting same error

                                              – androidTag
                                              Aug 27 '15 at 9:46











                                            • A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

                                              – CmosBattery
                                              Apr 22 '16 at 13:59














                                            8












                                            8








                                            8







                                            Resize your image before setup to ImageView like this:



                                            Bitmap.createScaledBitmap(_yourImageBitmap, _size, _size, false);


                                            where size is actual size of ImageView. You can reach size by measuring:



                                            imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));


                                            and use next size imageView.getMeasuredWidth() and imageView.getMeasuredHeight() for scaling.






                                            share|improve this answer















                                            Resize your image before setup to ImageView like this:



                                            Bitmap.createScaledBitmap(_yourImageBitmap, _size, _size, false);


                                            where size is actual size of ImageView. You can reach size by measuring:



                                            imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));


                                            and use next size imageView.getMeasuredWidth() and imageView.getMeasuredHeight() for scaling.







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Feb 8 '17 at 18:37









                                            Vinoth Vino

                                            3,20832739




                                            3,20832739










                                            answered Aug 27 '15 at 9:13









                                            Vladimir EremeevVladimir Eremeev

                                            1247




                                            1247













                                            • I have tried with this android:largeHeap="true" but getting same error

                                              – androidTag
                                              Aug 27 '15 at 9:46











                                            • A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

                                              – CmosBattery
                                              Apr 22 '16 at 13:59



















                                            • I have tried with this android:largeHeap="true" but getting same error

                                              – androidTag
                                              Aug 27 '15 at 9:46











                                            • A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

                                              – CmosBattery
                                              Apr 22 '16 at 13:59

















                                            I have tried with this android:largeHeap="true" but getting same error

                                            – androidTag
                                            Aug 27 '15 at 9:46





                                            I have tried with this android:largeHeap="true" but getting same error

                                            – androidTag
                                            Aug 27 '15 at 9:46













                                            A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

                                            – CmosBattery
                                            Apr 22 '16 at 13:59





                                            A further example of why this won't necessarily work (using private app storage): Placing a bitmap in res/drawable/ can give the same error but it won't happen every time. Placing same bitmap into res/drawable-xhdpi/ will no longer have the error. So as an answer, its not correct by itself.

                                            – CmosBattery
                                            Apr 22 '16 at 13:59











                                            4














                                            I have resolved this problem by resizing the image to lower size. I am using xamarin form. decreasing the size of the PNG image resolved the problem.






                                            share|improve this answer




























                                              4














                                              I have resolved this problem by resizing the image to lower size. I am using xamarin form. decreasing the size of the PNG image resolved the problem.






                                              share|improve this answer


























                                                4












                                                4








                                                4







                                                I have resolved this problem by resizing the image to lower size. I am using xamarin form. decreasing the size of the PNG image resolved the problem.






                                                share|improve this answer













                                                I have resolved this problem by resizing the image to lower size. I am using xamarin form. decreasing the size of the PNG image resolved the problem.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered May 2 '16 at 20:41









                                                maxspanmaxspan

                                                4,49243762




                                                4,49243762























                                                    3














                                                    I got below error




                                                    "E/art: Throwing OutOfMemoryError "Failed to allocate a 47251468 byte
                                                    allocation with 16777120 free bytes and 23MB until OOM"




                                                    after adding android:largeHeap="true" in AndroidManifest.xml then I rid of all the errors



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





                                                    share|improve this answer





















                                                    • 2





                                                      Didn't work for my case

                                                      – Sami Eltamawy
                                                      Nov 27 '16 at 12:05
















                                                    3














                                                    I got below error




                                                    "E/art: Throwing OutOfMemoryError "Failed to allocate a 47251468 byte
                                                    allocation with 16777120 free bytes and 23MB until OOM"




                                                    after adding android:largeHeap="true" in AndroidManifest.xml then I rid of all the errors



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





                                                    share|improve this answer





















                                                    • 2





                                                      Didn't work for my case

                                                      – Sami Eltamawy
                                                      Nov 27 '16 at 12:05














                                                    3












                                                    3








                                                    3







                                                    I got below error




                                                    "E/art: Throwing OutOfMemoryError "Failed to allocate a 47251468 byte
                                                    allocation with 16777120 free bytes and 23MB until OOM"




                                                    after adding android:largeHeap="true" in AndroidManifest.xml then I rid of all the errors



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





                                                    share|improve this answer















                                                    I got below error




                                                    "E/art: Throwing OutOfMemoryError "Failed to allocate a 47251468 byte
                                                    allocation with 16777120 free bytes and 23MB until OOM"




                                                    after adding android:largeHeap="true" in AndroidManifest.xml then I rid of all the errors



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






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Feb 6 '17 at 21:34









                                                    Vinoth Vino

                                                    3,20832739




                                                    3,20832739










                                                    answered Aug 15 '16 at 3:29









                                                    saigopisaigopi

                                                    3,7812523




                                                    3,7812523








                                                    • 2





                                                      Didn't work for my case

                                                      – Sami Eltamawy
                                                      Nov 27 '16 at 12:05














                                                    • 2





                                                      Didn't work for my case

                                                      – Sami Eltamawy
                                                      Nov 27 '16 at 12:05








                                                    2




                                                    2





                                                    Didn't work for my case

                                                    – Sami Eltamawy
                                                    Nov 27 '16 at 12:05





                                                    Didn't work for my case

                                                    – Sami Eltamawy
                                                    Nov 27 '16 at 12:05











                                                    3














                                                    Soluton try this in your Manifest File and use Glide Library



                                                    compile 'com.github.bumptech.glide:glide:3.7.0'



                                                        **Use Glide Library and Override size to less size;**

                                                    if (!TextUtils.isEmpty(message.getPicture())) {
                                                    Glide.with(mContext).load(message.getPicture())
                                                    .thumbnail(0.5f)
                                                    .crossFade()
                                                    .transform(new CircleTransform(mContext))
                                                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                                                    .into(holder.imgProfile);
                                                    }


                                                    android:hardwareAccelerated="false"



                                                    android:largeHeap="true"



                                                    <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">


                                                    Use this library



                                                      compile 'com.github.bumptech.glide:glide:3.7.0'   


                                                    Its Working Happy Coding



                                                    import android.content.Context;
                                                    import android.graphics.Bitmap;
                                                    import android.graphics.BitmapShader;
                                                    import android.graphics.Canvas;
                                                    import android.graphics.Paint;

                                                    import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
                                                    import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;


                                                    public class CircleTransform extends BitmapTransformation {
                                                    public CircleTransform(Context context) {
                                                    super(context);
                                                    }

                                                    @Override
                                                    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
                                                    return circleCrop(pool, toTransform);
                                                    }

                                                    private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
                                                    if (source == null) return null;

                                                    int size = Math.min(source.getWidth(), source.getHeight());
                                                    int x = (source.getWidth() - size) / 2;
                                                    int y = (source.getHeight() - size) / 2;

                                                    // TODO this could be acquired from the pool too
                                                    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

                                                    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
                                                    if (result == null) {
                                                    result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
                                                    }

                                                    Canvas canvas = new Canvas(result);
                                                    Paint paint = new Paint();
                                                    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
                                                    paint.setAntiAlias(true);
                                                    float r = size / 2f;
                                                    canvas.drawCircle(r, r, r, paint);
                                                    return result;
                                                    }

                                                    @Override
                                                    public String getId() {
                                                    return getClass().getName();
                                                    }
                                                    }





                                                    share|improve this answer






























                                                      3














                                                      Soluton try this in your Manifest File and use Glide Library



                                                      compile 'com.github.bumptech.glide:glide:3.7.0'



                                                          **Use Glide Library and Override size to less size;**

                                                      if (!TextUtils.isEmpty(message.getPicture())) {
                                                      Glide.with(mContext).load(message.getPicture())
                                                      .thumbnail(0.5f)
                                                      .crossFade()
                                                      .transform(new CircleTransform(mContext))
                                                      .diskCacheStrategy(DiskCacheStrategy.ALL)
                                                      .into(holder.imgProfile);
                                                      }


                                                      android:hardwareAccelerated="false"



                                                      android:largeHeap="true"



                                                      <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">


                                                      Use this library



                                                        compile 'com.github.bumptech.glide:glide:3.7.0'   


                                                      Its Working Happy Coding



                                                      import android.content.Context;
                                                      import android.graphics.Bitmap;
                                                      import android.graphics.BitmapShader;
                                                      import android.graphics.Canvas;
                                                      import android.graphics.Paint;

                                                      import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
                                                      import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;


                                                      public class CircleTransform extends BitmapTransformation {
                                                      public CircleTransform(Context context) {
                                                      super(context);
                                                      }

                                                      @Override
                                                      protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
                                                      return circleCrop(pool, toTransform);
                                                      }

                                                      private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
                                                      if (source == null) return null;

                                                      int size = Math.min(source.getWidth(), source.getHeight());
                                                      int x = (source.getWidth() - size) / 2;
                                                      int y = (source.getHeight() - size) / 2;

                                                      // TODO this could be acquired from the pool too
                                                      Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

                                                      Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
                                                      if (result == null) {
                                                      result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
                                                      }

                                                      Canvas canvas = new Canvas(result);
                                                      Paint paint = new Paint();
                                                      paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
                                                      paint.setAntiAlias(true);
                                                      float r = size / 2f;
                                                      canvas.drawCircle(r, r, r, paint);
                                                      return result;
                                                      }

                                                      @Override
                                                      public String getId() {
                                                      return getClass().getName();
                                                      }
                                                      }





                                                      share|improve this answer




























                                                        3












                                                        3








                                                        3







                                                        Soluton try this in your Manifest File and use Glide Library



                                                        compile 'com.github.bumptech.glide:glide:3.7.0'



                                                            **Use Glide Library and Override size to less size;**

                                                        if (!TextUtils.isEmpty(message.getPicture())) {
                                                        Glide.with(mContext).load(message.getPicture())
                                                        .thumbnail(0.5f)
                                                        .crossFade()
                                                        .transform(new CircleTransform(mContext))
                                                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                                                        .into(holder.imgProfile);
                                                        }


                                                        android:hardwareAccelerated="false"



                                                        android:largeHeap="true"



                                                        <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">


                                                        Use this library



                                                          compile 'com.github.bumptech.glide:glide:3.7.0'   


                                                        Its Working Happy Coding



                                                        import android.content.Context;
                                                        import android.graphics.Bitmap;
                                                        import android.graphics.BitmapShader;
                                                        import android.graphics.Canvas;
                                                        import android.graphics.Paint;

                                                        import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
                                                        import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;


                                                        public class CircleTransform extends BitmapTransformation {
                                                        public CircleTransform(Context context) {
                                                        super(context);
                                                        }

                                                        @Override
                                                        protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
                                                        return circleCrop(pool, toTransform);
                                                        }

                                                        private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
                                                        if (source == null) return null;

                                                        int size = Math.min(source.getWidth(), source.getHeight());
                                                        int x = (source.getWidth() - size) / 2;
                                                        int y = (source.getHeight() - size) / 2;

                                                        // TODO this could be acquired from the pool too
                                                        Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

                                                        Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
                                                        if (result == null) {
                                                        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
                                                        }

                                                        Canvas canvas = new Canvas(result);
                                                        Paint paint = new Paint();
                                                        paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
                                                        paint.setAntiAlias(true);
                                                        float r = size / 2f;
                                                        canvas.drawCircle(r, r, r, paint);
                                                        return result;
                                                        }

                                                        @Override
                                                        public String getId() {
                                                        return getClass().getName();
                                                        }
                                                        }





                                                        share|improve this answer















                                                        Soluton try this in your Manifest File and use Glide Library



                                                        compile 'com.github.bumptech.glide:glide:3.7.0'



                                                            **Use Glide Library and Override size to less size;**

                                                        if (!TextUtils.isEmpty(message.getPicture())) {
                                                        Glide.with(mContext).load(message.getPicture())
                                                        .thumbnail(0.5f)
                                                        .crossFade()
                                                        .transform(new CircleTransform(mContext))
                                                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                                                        .into(holder.imgProfile);
                                                        }


                                                        android:hardwareAccelerated="false"



                                                        android:largeHeap="true"



                                                        <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">


                                                        Use this library



                                                          compile 'com.github.bumptech.glide:glide:3.7.0'   


                                                        Its Working Happy Coding



                                                        import android.content.Context;
                                                        import android.graphics.Bitmap;
                                                        import android.graphics.BitmapShader;
                                                        import android.graphics.Canvas;
                                                        import android.graphics.Paint;

                                                        import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
                                                        import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;


                                                        public class CircleTransform extends BitmapTransformation {
                                                        public CircleTransform(Context context) {
                                                        super(context);
                                                        }

                                                        @Override
                                                        protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
                                                        return circleCrop(pool, toTransform);
                                                        }

                                                        private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
                                                        if (source == null) return null;

                                                        int size = Math.min(source.getWidth(), source.getHeight());
                                                        int x = (source.getWidth() - size) / 2;
                                                        int y = (source.getHeight() - size) / 2;

                                                        // TODO this could be acquired from the pool too
                                                        Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

                                                        Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
                                                        if (result == null) {
                                                        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
                                                        }

                                                        Canvas canvas = new Canvas(result);
                                                        Paint paint = new Paint();
                                                        paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
                                                        paint.setAntiAlias(true);
                                                        float r = size / 2f;
                                                        canvas.drawCircle(r, r, r, paint);
                                                        return result;
                                                        }

                                                        @Override
                                                        public String getId() {
                                                        return getClass().getName();
                                                        }
                                                        }






                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Aug 15 '17 at 17:57









                                                        Shreyas Sanil

                                                        139111




                                                        139111










                                                        answered Jul 17 '17 at 11:01









                                                        Keshav GeraKeshav Gera

                                                        2,9091828




                                                        2,9091828























                                                            3















                                                            Issue : Failed to allocate a 37748748 byte allocation with 16777120
                                                            free bytes and 17MB until OOM




                                                            Solution :
                                                            1.open your manifest file
                                                            2. inside application tag just add below two lines



                                                             android:hardwareAccelerated="false"
                                                            android:largeHeap="true"


                                                            Example :



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





                                                            share|improve this answer






























                                                              3















                                                              Issue : Failed to allocate a 37748748 byte allocation with 16777120
                                                              free bytes and 17MB until OOM




                                                              Solution :
                                                              1.open your manifest file
                                                              2. inside application tag just add below two lines



                                                               android:hardwareAccelerated="false"
                                                              android:largeHeap="true"


                                                              Example :



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





                                                              share|improve this answer




























                                                                3












                                                                3








                                                                3








                                                                Issue : Failed to allocate a 37748748 byte allocation with 16777120
                                                                free bytes and 17MB until OOM




                                                                Solution :
                                                                1.open your manifest file
                                                                2. inside application tag just add below two lines



                                                                 android:hardwareAccelerated="false"
                                                                android:largeHeap="true"


                                                                Example :



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





                                                                share|improve this answer
















                                                                Issue : Failed to allocate a 37748748 byte allocation with 16777120
                                                                free bytes and 17MB until OOM




                                                                Solution :
                                                                1.open your manifest file
                                                                2. inside application tag just add below two lines



                                                                 android:hardwareAccelerated="false"
                                                                android:largeHeap="true"


                                                                Example :



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






                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Nov 6 '17 at 11:28









                                                                King of Masses

                                                                12.6k44766




                                                                12.6k44766










                                                                answered Nov 6 '17 at 11:12









                                                                Kishore ReddyKishore Reddy

                                                                859810




                                                                859810























                                                                    2














                                                                    I had the problem too.



                                                                    Same with most of others above.
                                                                    The problem is caused by huge image.



                                                                    Just resize some images,
                                                                    and no need to change any code.






                                                                    share|improve this answer




























                                                                      2














                                                                      I had the problem too.



                                                                      Same with most of others above.
                                                                      The problem is caused by huge image.



                                                                      Just resize some images,
                                                                      and no need to change any code.






                                                                      share|improve this answer


























                                                                        2












                                                                        2








                                                                        2







                                                                        I had the problem too.



                                                                        Same with most of others above.
                                                                        The problem is caused by huge image.



                                                                        Just resize some images,
                                                                        and no need to change any code.






                                                                        share|improve this answer













                                                                        I had the problem too.



                                                                        Same with most of others above.
                                                                        The problem is caused by huge image.



                                                                        Just resize some images,
                                                                        and no need to change any code.







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Mar 9 '17 at 2:26









                                                                        Mike YanMike Yan

                                                                        1,29011015




                                                                        1,29011015























                                                                            1














                                                                            I'm a newbie in android developing but I hope my solution helps, it works on my condition perfectly. Im using Imageview and set it's background to "src" because im trying to make a frame animation. I got the same error but when I tried to code this it worked



                                                                            int ImageID = this.Resources.GetIdentifier(questionPlay[index].Image.ToLower(), "anim", PackageName);
                                                                            imgView.SetImageResource(ImageID);
                                                                            AnimationDrawable animation = (AnimationDrawable)imgView.Drawable;
                                                                            animation.Start();
                                                                            animation.Dispose();





                                                                            share|improve this answer




























                                                                              1














                                                                              I'm a newbie in android developing but I hope my solution helps, it works on my condition perfectly. Im using Imageview and set it's background to "src" because im trying to make a frame animation. I got the same error but when I tried to code this it worked



                                                                              int ImageID = this.Resources.GetIdentifier(questionPlay[index].Image.ToLower(), "anim", PackageName);
                                                                              imgView.SetImageResource(ImageID);
                                                                              AnimationDrawable animation = (AnimationDrawable)imgView.Drawable;
                                                                              animation.Start();
                                                                              animation.Dispose();





                                                                              share|improve this answer


























                                                                                1












                                                                                1








                                                                                1







                                                                                I'm a newbie in android developing but I hope my solution helps, it works on my condition perfectly. Im using Imageview and set it's background to "src" because im trying to make a frame animation. I got the same error but when I tried to code this it worked



                                                                                int ImageID = this.Resources.GetIdentifier(questionPlay[index].Image.ToLower(), "anim", PackageName);
                                                                                imgView.SetImageResource(ImageID);
                                                                                AnimationDrawable animation = (AnimationDrawable)imgView.Drawable;
                                                                                animation.Start();
                                                                                animation.Dispose();





                                                                                share|improve this answer













                                                                                I'm a newbie in android developing but I hope my solution helps, it works on my condition perfectly. Im using Imageview and set it's background to "src" because im trying to make a frame animation. I got the same error but when I tried to code this it worked



                                                                                int ImageID = this.Resources.GetIdentifier(questionPlay[index].Image.ToLower(), "anim", PackageName);
                                                                                imgView.SetImageResource(ImageID);
                                                                                AnimationDrawable animation = (AnimationDrawable)imgView.Drawable;
                                                                                animation.Start();
                                                                                animation.Dispose();






                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Feb 26 '17 at 8:24









                                                                                DianeFloresDianeFlores

                                                                                111




                                                                                111























                                                                                    1














                                                                                    In some cases (e.g. operations in a loop) garbage collector is slower than your code. You can use a helper method from this answer to wait for garbage collector.






                                                                                    share|improve this answer




























                                                                                      1














                                                                                      In some cases (e.g. operations in a loop) garbage collector is slower than your code. You can use a helper method from this answer to wait for garbage collector.






                                                                                      share|improve this answer


























                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        In some cases (e.g. operations in a loop) garbage collector is slower than your code. You can use a helper method from this answer to wait for garbage collector.






                                                                                        share|improve this answer













                                                                                        In some cases (e.g. operations in a loop) garbage collector is slower than your code. You can use a helper method from this answer to wait for garbage collector.







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Jun 20 '17 at 6:06









                                                                                        ZonZon

                                                                                        5,85044455




                                                                                        5,85044455























                                                                                            1














                                                                                            I ran into this problem when I didn't kill off my old activity when moving on to a new activity. I fixed it with finish();



                                                                                                Intent goToMain = new Intent(this,MainActivity.class);
                                                                                            startActivity(goToMain);
                                                                                            finish();





                                                                                            share|improve this answer




























                                                                                              1














                                                                                              I ran into this problem when I didn't kill off my old activity when moving on to a new activity. I fixed it with finish();



                                                                                                  Intent goToMain = new Intent(this,MainActivity.class);
                                                                                              startActivity(goToMain);
                                                                                              finish();





                                                                                              share|improve this answer


























                                                                                                1












                                                                                                1








                                                                                                1







                                                                                                I ran into this problem when I didn't kill off my old activity when moving on to a new activity. I fixed it with finish();



                                                                                                    Intent goToMain = new Intent(this,MainActivity.class);
                                                                                                startActivity(goToMain);
                                                                                                finish();





                                                                                                share|improve this answer













                                                                                                I ran into this problem when I didn't kill off my old activity when moving on to a new activity. I fixed it with finish();



                                                                                                    Intent goToMain = new Intent(this,MainActivity.class);
                                                                                                startActivity(goToMain);
                                                                                                finish();






                                                                                                share|improve this answer












                                                                                                share|improve this answer



                                                                                                share|improve this answer










                                                                                                answered Jul 3 '17 at 17:36









                                                                                                Jason HuJason Hu

                                                                                                212




                                                                                                212























                                                                                                    1














                                                                                                    This worked for me: just move images from drawable folder to drawable-hdpi.






                                                                                                    share|improve this answer
























                                                                                                    • what the explanation of this? why this moving works ?

                                                                                                      – Harun
                                                                                                      Apr 19 '18 at 5:04
















                                                                                                    1














                                                                                                    This worked for me: just move images from drawable folder to drawable-hdpi.






                                                                                                    share|improve this answer
























                                                                                                    • what the explanation of this? why this moving works ?

                                                                                                      – Harun
                                                                                                      Apr 19 '18 at 5:04














                                                                                                    1












                                                                                                    1








                                                                                                    1







                                                                                                    This worked for me: just move images from drawable folder to drawable-hdpi.






                                                                                                    share|improve this answer













                                                                                                    This worked for me: just move images from drawable folder to drawable-hdpi.







                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered Aug 14 '17 at 14:58









                                                                                                    Hossein AminiHossein Amini

                                                                                                    442519




                                                                                                    442519













                                                                                                    • what the explanation of this? why this moving works ?

                                                                                                      – Harun
                                                                                                      Apr 19 '18 at 5:04



















                                                                                                    • what the explanation of this? why this moving works ?

                                                                                                      – Harun
                                                                                                      Apr 19 '18 at 5:04

















                                                                                                    what the explanation of this? why this moving works ?

                                                                                                    – Harun
                                                                                                    Apr 19 '18 at 5:04





                                                                                                    what the explanation of this? why this moving works ?

                                                                                                    – Harun
                                                                                                    Apr 19 '18 at 5:04











                                                                                                    1














                                                                                                    Bitmap image =((BitmapDrawable)imageView1.getDrawable()).getBitmap();

                                                                                                    ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();

                                                                                                    image.compress(Bitmap.CompressFormat.JPEG,50/100,byteArrayOutputStream);


                                                                                                    50/100 if one uses 100 then original resolution can stopped the Apps for out of memory.



                                                                                                    if 50 or less than 100 this will be 50% or less than 100 resolution so this will prevent from out of memory problem






                                                                                                    share|improve this answer






























                                                                                                      1














                                                                                                      Bitmap image =((BitmapDrawable)imageView1.getDrawable()).getBitmap();

                                                                                                      ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();

                                                                                                      image.compress(Bitmap.CompressFormat.JPEG,50/100,byteArrayOutputStream);


                                                                                                      50/100 if one uses 100 then original resolution can stopped the Apps for out of memory.



                                                                                                      if 50 or less than 100 this will be 50% or less than 100 resolution so this will prevent from out of memory problem






                                                                                                      share|improve this answer




























                                                                                                        1












                                                                                                        1








                                                                                                        1







                                                                                                        Bitmap image =((BitmapDrawable)imageView1.getDrawable()).getBitmap();

                                                                                                        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();

                                                                                                        image.compress(Bitmap.CompressFormat.JPEG,50/100,byteArrayOutputStream);


                                                                                                        50/100 if one uses 100 then original resolution can stopped the Apps for out of memory.



                                                                                                        if 50 or less than 100 this will be 50% or less than 100 resolution so this will prevent from out of memory problem






                                                                                                        share|improve this answer















                                                                                                        Bitmap image =((BitmapDrawable)imageView1.getDrawable()).getBitmap();

                                                                                                        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();

                                                                                                        image.compress(Bitmap.CompressFormat.JPEG,50/100,byteArrayOutputStream);


                                                                                                        50/100 if one uses 100 then original resolution can stopped the Apps for out of memory.



                                                                                                        if 50 or less than 100 this will be 50% or less than 100 resolution so this will prevent from out of memory problem







                                                                                                        share|improve this answer














                                                                                                        share|improve this answer



                                                                                                        share|improve this answer








                                                                                                        edited Nov 6 '17 at 11:29









                                                                                                        King of Masses

                                                                                                        12.6k44766




                                                                                                        12.6k44766










                                                                                                        answered Jun 7 '17 at 6:09









                                                                                                        RAHINUR RAHMANRAHINUR RAHMAN

                                                                                                        515




                                                                                                        515























                                                                                                            1














                                                                                                            I have found that images in the 'drawable' folder will get converted to a much larger image on high def phones. For example, a 200k image will be resampled to a higher res, like 800k or 32000k. I had to discover this on my own and to date have not seen documentation for this heap memory trap. To prevent this I put everything in a drawable-nodpi folder (in addition to using 'options' in BitmapFactory based on the particular device heap). I can't afford to have the size of my app bloated with multiple drawable folders, particularly as the range of screen defs is so vast now. The tricky thing is studio now doesn't specifically indicate the 'drawable-nodpi' folder as such in the project view, it just shows a 'drawable' folder. If you're not careful, when you drop an image to this folder in studio, it won't actually get dropped into the drawable-nodpi:



                                                                                                            Careful here 'backgroundtest' did not actually go to drawable-nodpi and will 
                                                                                                            be resampled higher, such as 4x or 16x of the original dimensions for high def screens.


                                                                                                            enter image description here



                                                                                                            Be sure to click down to the nodpi folder in the dialogue, as the project view won't show you all drawable folders separately like it used to, so it won't be immediately apparent that it went to wrong one. Studio recreated the vanilla 'drawable' at some point for me after I had deleted it long ago:



                                                                                                            enter image description here






                                                                                                            share|improve this answer






























                                                                                                              1














                                                                                                              I have found that images in the 'drawable' folder will get converted to a much larger image on high def phones. For example, a 200k image will be resampled to a higher res, like 800k or 32000k. I had to discover this on my own and to date have not seen documentation for this heap memory trap. To prevent this I put everything in a drawable-nodpi folder (in addition to using 'options' in BitmapFactory based on the particular device heap). I can't afford to have the size of my app bloated with multiple drawable folders, particularly as the range of screen defs is so vast now. The tricky thing is studio now doesn't specifically indicate the 'drawable-nodpi' folder as such in the project view, it just shows a 'drawable' folder. If you're not careful, when you drop an image to this folder in studio, it won't actually get dropped into the drawable-nodpi:



                                                                                                              Careful here 'backgroundtest' did not actually go to drawable-nodpi and will 
                                                                                                              be resampled higher, such as 4x or 16x of the original dimensions for high def screens.


                                                                                                              enter image description here



                                                                                                              Be sure to click down to the nodpi folder in the dialogue, as the project view won't show you all drawable folders separately like it used to, so it won't be immediately apparent that it went to wrong one. Studio recreated the vanilla 'drawable' at some point for me after I had deleted it long ago:



                                                                                                              enter image description here






                                                                                                              share|improve this answer




























                                                                                                                1












                                                                                                                1








                                                                                                                1







                                                                                                                I have found that images in the 'drawable' folder will get converted to a much larger image on high def phones. For example, a 200k image will be resampled to a higher res, like 800k or 32000k. I had to discover this on my own and to date have not seen documentation for this heap memory trap. To prevent this I put everything in a drawable-nodpi folder (in addition to using 'options' in BitmapFactory based on the particular device heap). I can't afford to have the size of my app bloated with multiple drawable folders, particularly as the range of screen defs is so vast now. The tricky thing is studio now doesn't specifically indicate the 'drawable-nodpi' folder as such in the project view, it just shows a 'drawable' folder. If you're not careful, when you drop an image to this folder in studio, it won't actually get dropped into the drawable-nodpi:



                                                                                                                Careful here 'backgroundtest' did not actually go to drawable-nodpi and will 
                                                                                                                be resampled higher, such as 4x or 16x of the original dimensions for high def screens.


                                                                                                                enter image description here



                                                                                                                Be sure to click down to the nodpi folder in the dialogue, as the project view won't show you all drawable folders separately like it used to, so it won't be immediately apparent that it went to wrong one. Studio recreated the vanilla 'drawable' at some point for me after I had deleted it long ago:



                                                                                                                enter image description here






                                                                                                                share|improve this answer















                                                                                                                I have found that images in the 'drawable' folder will get converted to a much larger image on high def phones. For example, a 200k image will be resampled to a higher res, like 800k or 32000k. I had to discover this on my own and to date have not seen documentation for this heap memory trap. To prevent this I put everything in a drawable-nodpi folder (in addition to using 'options' in BitmapFactory based on the particular device heap). I can't afford to have the size of my app bloated with multiple drawable folders, particularly as the range of screen defs is so vast now. The tricky thing is studio now doesn't specifically indicate the 'drawable-nodpi' folder as such in the project view, it just shows a 'drawable' folder. If you're not careful, when you drop an image to this folder in studio, it won't actually get dropped into the drawable-nodpi:



                                                                                                                Careful here 'backgroundtest' did not actually go to drawable-nodpi and will 
                                                                                                                be resampled higher, such as 4x or 16x of the original dimensions for high def screens.


                                                                                                                enter image description here



                                                                                                                Be sure to click down to the nodpi folder in the dialogue, as the project view won't show you all drawable folders separately like it used to, so it won't be immediately apparent that it went to wrong one. Studio recreated the vanilla 'drawable' at some point for me after I had deleted it long ago:



                                                                                                                enter image description here







                                                                                                                share|improve this answer














                                                                                                                share|improve this answer



                                                                                                                share|improve this answer








                                                                                                                edited Nov 12 '17 at 18:50

























                                                                                                                answered Nov 12 '17 at 16:07









                                                                                                                AndroidcoderAndroidcoder

                                                                                                                2,30031832




                                                                                                                2,30031832























                                                                                                                    1














                                                                                                                    You have to change the size of object in drawable. It's too big for android to display. e.g. If you are setting image try image with less pixels. It works for me.
                                                                                                                    Thanks. :)






                                                                                                                    share|improve this answer




























                                                                                                                      1














                                                                                                                      You have to change the size of object in drawable. It's too big for android to display. e.g. If you are setting image try image with less pixels. It works for me.
                                                                                                                      Thanks. :)






                                                                                                                      share|improve this answer


























                                                                                                                        1












                                                                                                                        1








                                                                                                                        1







                                                                                                                        You have to change the size of object in drawable. It's too big for android to display. e.g. If you are setting image try image with less pixels. It works for me.
                                                                                                                        Thanks. :)






                                                                                                                        share|improve this answer













                                                                                                                        You have to change the size of object in drawable. It's too big for android to display. e.g. If you are setting image try image with less pixels. It works for me.
                                                                                                                        Thanks. :)







                                                                                                                        share|improve this answer












                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer










                                                                                                                        answered Jan 31 '18 at 11:29









                                                                                                                        Ali Hassan QureshiAli Hassan Qureshi

                                                                                                                        5110




                                                                                                                        5110























                                                                                                                            1














                                                                                                                            Your app is crashing because your image size (in MB Or KB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size.



                                                                                                                            OR



                                                                                                                            You can add Following in application tag at Manifest.xml



                                                                                                                             android:hardwareAccelerated="false"
                                                                                                                            android:largeHeap="true"
                                                                                                                            android:allowBackup="true"


                                                                                                                            After Adding this App will not Crash.




                                                                                                                            • always use less sizes images in App.

                                                                                                                            • If You adding large sizes of images in app , you should add above syntex, but App size will increase.






                                                                                                                            share|improve this answer




























                                                                                                                              1














                                                                                                                              Your app is crashing because your image size (in MB Or KB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size.



                                                                                                                              OR



                                                                                                                              You can add Following in application tag at Manifest.xml



                                                                                                                               android:hardwareAccelerated="false"
                                                                                                                              android:largeHeap="true"
                                                                                                                              android:allowBackup="true"


                                                                                                                              After Adding this App will not Crash.




                                                                                                                              • always use less sizes images in App.

                                                                                                                              • If You adding large sizes of images in app , you should add above syntex, but App size will increase.






                                                                                                                              share|improve this answer


























                                                                                                                                1












                                                                                                                                1








                                                                                                                                1







                                                                                                                                Your app is crashing because your image size (in MB Or KB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size.



                                                                                                                                OR



                                                                                                                                You can add Following in application tag at Manifest.xml



                                                                                                                                 android:hardwareAccelerated="false"
                                                                                                                                android:largeHeap="true"
                                                                                                                                android:allowBackup="true"


                                                                                                                                After Adding this App will not Crash.




                                                                                                                                • always use less sizes images in App.

                                                                                                                                • If You adding large sizes of images in app , you should add above syntex, but App size will increase.






                                                                                                                                share|improve this answer













                                                                                                                                Your app is crashing because your image size (in MB Or KB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size.



                                                                                                                                OR



                                                                                                                                You can add Following in application tag at Manifest.xml



                                                                                                                                 android:hardwareAccelerated="false"
                                                                                                                                android:largeHeap="true"
                                                                                                                                android:allowBackup="true"


                                                                                                                                After Adding this App will not Crash.




                                                                                                                                • always use less sizes images in App.

                                                                                                                                • If You adding large sizes of images in app , you should add above syntex, but App size will increase.







                                                                                                                                share|improve this answer












                                                                                                                                share|improve this answer



                                                                                                                                share|improve this answer










                                                                                                                                answered Jul 23 '18 at 7:45









                                                                                                                                rhaldarrhaldar

                                                                                                                                814




                                                                                                                                814























                                                                                                                                    1














                                                                                                                                    My problem solved after adding



                                                                                                                                     dexOptions {
                                                                                                                                    incremental true
                                                                                                                                    javaMaxHeapSize "4g"
                                                                                                                                    preDexLibraries true
                                                                                                                                    dexInProcess = true
                                                                                                                                    }


                                                                                                                                    in Build.Gradle file






                                                                                                                                    share|improve this answer
























                                                                                                                                    • This just makes your app really bloated in memory usage

                                                                                                                                      – cricket_007
                                                                                                                                      Oct 27 '18 at 18:14
















                                                                                                                                    1














                                                                                                                                    My problem solved after adding



                                                                                                                                     dexOptions {
                                                                                                                                    incremental true
                                                                                                                                    javaMaxHeapSize "4g"
                                                                                                                                    preDexLibraries true
                                                                                                                                    dexInProcess = true
                                                                                                                                    }


                                                                                                                                    in Build.Gradle file






                                                                                                                                    share|improve this answer
























                                                                                                                                    • This just makes your app really bloated in memory usage

                                                                                                                                      – cricket_007
                                                                                                                                      Oct 27 '18 at 18:14














                                                                                                                                    1












                                                                                                                                    1








                                                                                                                                    1







                                                                                                                                    My problem solved after adding



                                                                                                                                     dexOptions {
                                                                                                                                    incremental true
                                                                                                                                    javaMaxHeapSize "4g"
                                                                                                                                    preDexLibraries true
                                                                                                                                    dexInProcess = true
                                                                                                                                    }


                                                                                                                                    in Build.Gradle file






                                                                                                                                    share|improve this answer













                                                                                                                                    My problem solved after adding



                                                                                                                                     dexOptions {
                                                                                                                                    incremental true
                                                                                                                                    javaMaxHeapSize "4g"
                                                                                                                                    preDexLibraries true
                                                                                                                                    dexInProcess = true
                                                                                                                                    }


                                                                                                                                    in Build.Gradle file







                                                                                                                                    share|improve this answer












                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer










                                                                                                                                    answered Aug 13 '18 at 14:16









                                                                                                                                    MidhilajMidhilaj

                                                                                                                                    8151722




                                                                                                                                    8151722













                                                                                                                                    • This just makes your app really bloated in memory usage

                                                                                                                                      – cricket_007
                                                                                                                                      Oct 27 '18 at 18:14



















                                                                                                                                    • This just makes your app really bloated in memory usage

                                                                                                                                      – cricket_007
                                                                                                                                      Oct 27 '18 at 18:14

















                                                                                                                                    This just makes your app really bloated in memory usage

                                                                                                                                    – cricket_007
                                                                                                                                    Oct 27 '18 at 18:14





                                                                                                                                    This just makes your app really bloated in memory usage

                                                                                                                                    – cricket_007
                                                                                                                                    Oct 27 '18 at 18:14











                                                                                                                                    0














                                                                                                                                    If uploading an image, try reducing the image quality, which is the second parameter of the Bitmap. This was the solution in my case. Previously it was 90, then I tried with 60 (as it is in the code below now).



                                                                                                                                    Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
                                                                                                                                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                                                                                    finalBitmap.compress(Bitmap.CompressFormat.JPEG,60,baos);
                                                                                                                                    byte b = baos.toByteArray();





                                                                                                                                    share|improve this answer




























                                                                                                                                      0














                                                                                                                                      If uploading an image, try reducing the image quality, which is the second parameter of the Bitmap. This was the solution in my case. Previously it was 90, then I tried with 60 (as it is in the code below now).



                                                                                                                                      Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
                                                                                                                                      ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                                                                                      finalBitmap.compress(Bitmap.CompressFormat.JPEG,60,baos);
                                                                                                                                      byte b = baos.toByteArray();





                                                                                                                                      share|improve this answer


























                                                                                                                                        0












                                                                                                                                        0








                                                                                                                                        0







                                                                                                                                        If uploading an image, try reducing the image quality, which is the second parameter of the Bitmap. This was the solution in my case. Previously it was 90, then I tried with 60 (as it is in the code below now).



                                                                                                                                        Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
                                                                                                                                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                                                                                        finalBitmap.compress(Bitmap.CompressFormat.JPEG,60,baos);
                                                                                                                                        byte b = baos.toByteArray();





                                                                                                                                        share|improve this answer













                                                                                                                                        If uploading an image, try reducing the image quality, which is the second parameter of the Bitmap. This was the solution in my case. Previously it was 90, then I tried with 60 (as it is in the code below now).



                                                                                                                                        Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
                                                                                                                                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                                                                                        finalBitmap.compress(Bitmap.CompressFormat.JPEG,60,baos);
                                                                                                                                        byte b = baos.toByteArray();






                                                                                                                                        share|improve this answer












                                                                                                                                        share|improve this answer



                                                                                                                                        share|improve this answer










                                                                                                                                        answered Jul 1 '16 at 12:39









                                                                                                                                        Teo MihailaTeo Mihaila

                                                                                                                                        59113




                                                                                                                                        59113























                                                                                                                                            0














                                                                                                                                            Try the simplest one. Maybe Your app is crashing because your image size (in MB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size by any viewer software or if you are taking image from gallery at the run time than before saving it compress your bitmap.
                                                                                                                                            It worked for me. definitely for u will be.






                                                                                                                                            share|improve this answer






























                                                                                                                                              0














                                                                                                                                              Try the simplest one. Maybe Your app is crashing because your image size (in MB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size by any viewer software or if you are taking image from gallery at the run time than before saving it compress your bitmap.
                                                                                                                                              It worked for me. definitely for u will be.






                                                                                                                                              share|improve this answer




























                                                                                                                                                0












                                                                                                                                                0








                                                                                                                                                0







                                                                                                                                                Try the simplest one. Maybe Your app is crashing because your image size (in MB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size by any viewer software or if you are taking image from gallery at the run time than before saving it compress your bitmap.
                                                                                                                                                It worked for me. definitely for u will be.






                                                                                                                                                share|improve this answer















                                                                                                                                                Try the simplest one. Maybe Your app is crashing because your image size (in MB) is too large so it is not allocating space for that. So before pasting your image in drawable just reduce the size by any viewer software or if you are taking image from gallery at the run time than before saving it compress your bitmap.
                                                                                                                                                It worked for me. definitely for u will be.







                                                                                                                                                share|improve this answer














                                                                                                                                                share|improve this answer



                                                                                                                                                share|improve this answer








                                                                                                                                                edited Jun 18 '17 at 10:27









                                                                                                                                                yakobom

                                                                                                                                                2,19111928




                                                                                                                                                2,19111928










                                                                                                                                                answered Jun 18 '17 at 7:52









                                                                                                                                                neensneens

                                                                                                                                                155




                                                                                                                                                155























                                                                                                                                                    0














                                                                                                                                                    stream = activity.getContentResolver().openInputStream(uri);
                                                                                                                                                    BitmapFactory.Options options = new BitmapFactory.Options();
                                                                                                                                                    options.inPreferredConfig = Bitmap.Config.RGB_565;

                                                                                                                                                    bitmap = BitmapFactory.decodeStream(stream, null, options);
                                                                                                                                                    int Height = bitmap.getHeight();
                                                                                                                                                    int Width = bitmap.getWidth();
                                                                                                                                                    enter code here
                                                                                                                                                    int newHeight = 1000;
                                                                                                                                                    float scaleFactor = ((float) newHeight) / Height;
                                                                                                                                                    float newWidth = Width * scaleFactor;

                                                                                                                                                    float scaleWidth = scaleFactor;
                                                                                                                                                    float scaleHeight = scaleFactor;
                                                                                                                                                    Matrix matrix = new Matrix();
                                                                                                                                                    matrix.postScale(scaleWidth, scaleHeight);
                                                                                                                                                    resizedBitmap= Bitmap.createBitmap(bitmap, 0, 0,Width, Height, matrix, true);
                                                                                                                                                    bitmap.recycle();


                                                                                                                                                    Then in Appliaction tag, add largeheapsize="true






                                                                                                                                                    share|improve this answer






























                                                                                                                                                      0














                                                                                                                                                      stream = activity.getContentResolver().openInputStream(uri);
                                                                                                                                                      BitmapFactory.Options options = new BitmapFactory.Options();
                                                                                                                                                      options.inPreferredConfig = Bitmap.Config.RGB_565;

                                                                                                                                                      bitmap = BitmapFactory.decodeStream(stream, null, options);
                                                                                                                                                      int Height = bitmap.getHeight();
                                                                                                                                                      int Width = bitmap.getWidth();
                                                                                                                                                      enter code here
                                                                                                                                                      int newHeight = 1000;
                                                                                                                                                      float scaleFactor = ((float) newHeight) / Height;
                                                                                                                                                      float newWidth = Width * scaleFactor;

                                                                                                                                                      float scaleWidth = scaleFactor;
                                                                                                                                                      float scaleHeight = scaleFactor;
                                                                                                                                                      Matrix matrix = new Matrix();
                                                                                                                                                      matrix.postScale(scaleWidth, scaleHeight);
                                                                                                                                                      resizedBitmap= Bitmap.createBitmap(bitmap, 0, 0,Width, Height, matrix, true);
                                                                                                                                                      bitmap.recycle();


                                                                                                                                                      Then in Appliaction tag, add largeheapsize="true






                                                                                                                                                      share|improve this answer




























                                                                                                                                                        0












                                                                                                                                                        0








                                                                                                                                                        0







                                                                                                                                                        stream = activity.getContentResolver().openInputStream(uri);
                                                                                                                                                        BitmapFactory.Options options = new BitmapFactory.Options();
                                                                                                                                                        options.inPreferredConfig = Bitmap.Config.RGB_565;

                                                                                                                                                        bitmap = BitmapFactory.decodeStream(stream, null, options);
                                                                                                                                                        int Height = bitmap.getHeight();
                                                                                                                                                        int Width = bitmap.getWidth();
                                                                                                                                                        enter code here
                                                                                                                                                        int newHeight = 1000;
                                                                                                                                                        float scaleFactor = ((float) newHeight) / Height;
                                                                                                                                                        float newWidth = Width * scaleFactor;

                                                                                                                                                        float scaleWidth = scaleFactor;
                                                                                                                                                        float scaleHeight = scaleFactor;
                                                                                                                                                        Matrix matrix = new Matrix();
                                                                                                                                                        matrix.postScale(scaleWidth, scaleHeight);
                                                                                                                                                        resizedBitmap= Bitmap.createBitmap(bitmap, 0, 0,Width, Height, matrix, true);
                                                                                                                                                        bitmap.recycle();


                                                                                                                                                        Then in Appliaction tag, add largeheapsize="true






                                                                                                                                                        share|improve this answer















                                                                                                                                                        stream = activity.getContentResolver().openInputStream(uri);
                                                                                                                                                        BitmapFactory.Options options = new BitmapFactory.Options();
                                                                                                                                                        options.inPreferredConfig = Bitmap.Config.RGB_565;

                                                                                                                                                        bitmap = BitmapFactory.decodeStream(stream, null, options);
                                                                                                                                                        int Height = bitmap.getHeight();
                                                                                                                                                        int Width = bitmap.getWidth();
                                                                                                                                                        enter code here
                                                                                                                                                        int newHeight = 1000;
                                                                                                                                                        float scaleFactor = ((float) newHeight) / Height;
                                                                                                                                                        float newWidth = Width * scaleFactor;

                                                                                                                                                        float scaleWidth = scaleFactor;
                                                                                                                                                        float scaleHeight = scaleFactor;
                                                                                                                                                        Matrix matrix = new Matrix();
                                                                                                                                                        matrix.postScale(scaleWidth, scaleHeight);
                                                                                                                                                        resizedBitmap= Bitmap.createBitmap(bitmap, 0, 0,Width, Height, matrix, true);
                                                                                                                                                        bitmap.recycle();


                                                                                                                                                        Then in Appliaction tag, add largeheapsize="true







                                                                                                                                                        share|improve this answer














                                                                                                                                                        share|improve this answer



                                                                                                                                                        share|improve this answer








                                                                                                                                                        edited Oct 8 '18 at 4:55









                                                                                                                                                        Pang

                                                                                                                                                        6,9511664103




                                                                                                                                                        6,9511664103










                                                                                                                                                        answered Sep 21 '18 at 10:28









                                                                                                                                                        sathish mobapp devsathish mobapp dev

                                                                                                                                                        785




                                                                                                                                                        785























                                                                                                                                                            0














                                                                                                                                                            Last but not the least....

                                                                                                                                                            Try Method One:

                                                                                                                                                            Simple Add these lines of code in the gradle file

                                                                                                                                                            dexOptions {
                                                                                                                                                            incremental true
                                                                                                                                                            javaMaxHeapSize "4g"
                                                                                                                                                            }

                                                                                                                                                            Example:

                                                                                                                                                            android {
                                                                                                                                                            compileSdkVersion XX
                                                                                                                                                            buildToolsVersion "28.X.X"

                                                                                                                                                            defaultConfig {
                                                                                                                                                            applicationId "com.example.xxxxx"
                                                                                                                                                            minSdkVersion 14
                                                                                                                                                            targetSdkVersion 19
                                                                                                                                                            }

                                                                                                                                                            dexOptions {
                                                                                                                                                            incremental true
                                                                                                                                                            javaMaxHeapSize "4g"
                                                                                                                                                            }
                                                                                                                                                            }

                                                                                                                                                            *******************************************************************

                                                                                                                                                            Method Two:

                                                                                                                                                            Add these two lines of code in manifest file...

                                                                                                                                                            android:hardwareAccelerated="false"
                                                                                                                                                            android:largeHeap="true"

                                                                                                                                                            Example:

                                                                                                                                                            <application
                                                                                                                                                            android:allowBackup="true"
                                                                                                                                                            android:icon="@drawable/ic_launcher"
                                                                                                                                                            android:hardwareAccelerated="false"
                                                                                                                                                            android:largeHeap="true"
                                                                                                                                                            android:label="@string/app_name"
                                                                                                                                                            android:theme="@style/AppTheme" >
                                                                                                                                                            <activity
                                                                                                                                                            android:name=".MainActivity"
                                                                                                                                                            android:label="@string/app_name" >
                                                                                                                                                            <intent-filter>
                                                                                                                                                            <action android:name="android.intent.action.MAIN" />

                                                                                                                                                            <category android:name="android.intent.category.LAUNCHER" />
                                                                                                                                                            </intent-filter>
                                                                                                                                                            </activity>
                                                                                                                                                            </application>

                                                                                                                                                            It will Work for sure any of these cases.....





                                                                                                                                                            share|improve this answer




























                                                                                                                                                              0














                                                                                                                                                              Last but not the least....

                                                                                                                                                              Try Method One:

                                                                                                                                                              Simple Add these lines of code in the gradle file

                                                                                                                                                              dexOptions {
                                                                                                                                                              incremental true
                                                                                                                                                              javaMaxHeapSize "4g"
                                                                                                                                                              }

                                                                                                                                                              Example:

                                                                                                                                                              android {
                                                                                                                                                              compileSdkVersion XX
                                                                                                                                                              buildToolsVersion "28.X.X"

                                                                                                                                                              defaultConfig {
                                                                                                                                                              applicationId "com.example.xxxxx"
                                                                                                                                                              minSdkVersion 14
                                                                                                                                                              targetSdkVersion 19
                                                                                                                                                              }

                                                                                                                                                              dexOptions {
                                                                                                                                                              incremental true
                                                                                                                                                              javaMaxHeapSize "4g"
                                                                                                                                                              }
                                                                                                                                                              }

                                                                                                                                                              *******************************************************************

                                                                                                                                                              Method Two:

                                                                                                                                                              Add these two lines of code in manifest file...

                                                                                                                                                              android:hardwareAccelerated="false"
                                                                                                                                                              android:largeHeap="true"

                                                                                                                                                              Example:

                                                                                                                                                              <application
                                                                                                                                                              android:allowBackup="true"
                                                                                                                                                              android:icon="@drawable/ic_launcher"
                                                                                                                                                              android:hardwareAccelerated="false"
                                                                                                                                                              android:largeHeap="true"
                                                                                                                                                              android:label="@string/app_name"
                                                                                                                                                              android:theme="@style/AppTheme" >
                                                                                                                                                              <activity
                                                                                                                                                              android:name=".MainActivity"
                                                                                                                                                              android:label="@string/app_name" >
                                                                                                                                                              <intent-filter>
                                                                                                                                                              <action android:name="android.intent.action.MAIN" />

                                                                                                                                                              <category android:name="android.intent.category.LAUNCHER" />
                                                                                                                                                              </intent-filter>
                                                                                                                                                              </activity>
                                                                                                                                                              </application>

                                                                                                                                                              It will Work for sure any of these cases.....





                                                                                                                                                              share|improve this answer


























                                                                                                                                                                0












                                                                                                                                                                0








                                                                                                                                                                0







                                                                                                                                                                Last but not the least....

                                                                                                                                                                Try Method One:

                                                                                                                                                                Simple Add these lines of code in the gradle file

                                                                                                                                                                dexOptions {
                                                                                                                                                                incremental true
                                                                                                                                                                javaMaxHeapSize "4g"
                                                                                                                                                                }

                                                                                                                                                                Example:

                                                                                                                                                                android {
                                                                                                                                                                compileSdkVersion XX
                                                                                                                                                                buildToolsVersion "28.X.X"

                                                                                                                                                                defaultConfig {
                                                                                                                                                                applicationId "com.example.xxxxx"
                                                                                                                                                                minSdkVersion 14
                                                                                                                                                                targetSdkVersion 19
                                                                                                                                                                }

                                                                                                                                                                dexOptions {
                                                                                                                                                                incremental true
                                                                                                                                                                javaMaxHeapSize "4g"
                                                                                                                                                                }
                                                                                                                                                                }

                                                                                                                                                                *******************************************************************

                                                                                                                                                                Method Two:

                                                                                                                                                                Add these two lines of code in manifest file...

                                                                                                                                                                android:hardwareAccelerated="false"
                                                                                                                                                                android:largeHeap="true"

                                                                                                                                                                Example:

                                                                                                                                                                <application
                                                                                                                                                                android:allowBackup="true"
                                                                                                                                                                android:icon="@drawable/ic_launcher"
                                                                                                                                                                android:hardwareAccelerated="false"
                                                                                                                                                                android:largeHeap="true"
                                                                                                                                                                android:label="@string/app_name"
                                                                                                                                                                android:theme="@style/AppTheme" >
                                                                                                                                                                <activity
                                                                                                                                                                android:name=".MainActivity"
                                                                                                                                                                android:label="@string/app_name" >
                                                                                                                                                                <intent-filter>
                                                                                                                                                                <action android:name="android.intent.action.MAIN" />

                                                                                                                                                                <category android:name="android.intent.category.LAUNCHER" />
                                                                                                                                                                </intent-filter>
                                                                                                                                                                </activity>
                                                                                                                                                                </application>

                                                                                                                                                                It will Work for sure any of these cases.....





                                                                                                                                                                share|improve this answer













                                                                                                                                                                Last but not the least....

                                                                                                                                                                Try Method One:

                                                                                                                                                                Simple Add these lines of code in the gradle file

                                                                                                                                                                dexOptions {
                                                                                                                                                                incremental true
                                                                                                                                                                javaMaxHeapSize "4g"
                                                                                                                                                                }

                                                                                                                                                                Example:

                                                                                                                                                                android {
                                                                                                                                                                compileSdkVersion XX
                                                                                                                                                                buildToolsVersion "28.X.X"

                                                                                                                                                                defaultConfig {
                                                                                                                                                                applicationId "com.example.xxxxx"
                                                                                                                                                                minSdkVersion 14
                                                                                                                                                                targetSdkVersion 19
                                                                                                                                                                }

                                                                                                                                                                dexOptions {
                                                                                                                                                                incremental true
                                                                                                                                                                javaMaxHeapSize "4g"
                                                                                                                                                                }
                                                                                                                                                                }

                                                                                                                                                                *******************************************************************

                                                                                                                                                                Method Two:

                                                                                                                                                                Add these two lines of code in manifest file...

                                                                                                                                                                android:hardwareAccelerated="false"
                                                                                                                                                                android:largeHeap="true"

                                                                                                                                                                Example:

                                                                                                                                                                <application
                                                                                                                                                                android:allowBackup="true"
                                                                                                                                                                android:icon="@drawable/ic_launcher"
                                                                                                                                                                android:hardwareAccelerated="false"
                                                                                                                                                                android:largeHeap="true"
                                                                                                                                                                android:label="@string/app_name"
                                                                                                                                                                android:theme="@style/AppTheme" >
                                                                                                                                                                <activity
                                                                                                                                                                android:name=".MainActivity"
                                                                                                                                                                android:label="@string/app_name" >
                                                                                                                                                                <intent-filter>
                                                                                                                                                                <action android:name="android.intent.action.MAIN" />

                                                                                                                                                                <category android:name="android.intent.category.LAUNCHER" />
                                                                                                                                                                </intent-filter>
                                                                                                                                                                </activity>
                                                                                                                                                                </application>

                                                                                                                                                                It will Work for sure any of these cases.....






                                                                                                                                                                share|improve this answer












                                                                                                                                                                share|improve this answer



                                                                                                                                                                share|improve this answer










                                                                                                                                                                answered Nov 30 '18 at 9:59









                                                                                                                                                                Ambilpura Sunil KumarAmbilpura Sunil Kumar

                                                                                                                                                                17712




                                                                                                                                                                17712























                                                                                                                                                                    0














                                                                                                                                                                    Use an image loading library like Picasso or Glide. Using these libraries will prevent crashes in the future.






                                                                                                                                                                    share|improve this answer




























                                                                                                                                                                      0














                                                                                                                                                                      Use an image loading library like Picasso or Glide. Using these libraries will prevent crashes in the future.






                                                                                                                                                                      share|improve this answer


























                                                                                                                                                                        0












                                                                                                                                                                        0








                                                                                                                                                                        0







                                                                                                                                                                        Use an image loading library like Picasso or Glide. Using these libraries will prevent crashes in the future.






                                                                                                                                                                        share|improve this answer













                                                                                                                                                                        Use an image loading library like Picasso or Glide. Using these libraries will prevent crashes in the future.







                                                                                                                                                                        share|improve this answer












                                                                                                                                                                        share|improve this answer



                                                                                                                                                                        share|improve this answer










                                                                                                                                                                        answered Jan 15 at 16:27









                                                                                                                                                                        Vladyslav PanchenkoVladyslav Panchenko

                                                                                                                                                                        15617




                                                                                                                                                                        15617

















                                                                                                                                                                            protected by Community Aug 26 '17 at 0:17



                                                                                                                                                                            Thank you for your interest in this question.
                                                                                                                                                                            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                                                                                                            Would you like to answer one of these unanswered questions instead?



                                                                                                                                                                            Popular posts from this blog

                                                                                                                                                                            404 Error Contact Form 7 ajax form submitting

                                                                                                                                                                            How to know if a Active Directory user can login interactively

                                                                                                                                                                            TypeError: fit_transform() missing 1 required positional argument: 'X'