Java.lang.outofmemoryerror Even In A Try-catch Block?
My application crashes, showing this in logcat: java.lang.OutOfMemoryError: (Heap Size=39047KB, Allocated=19932KB) at android.graphics.BitmapFactory.nativeDecodeFile(Native
Solution 1:
Place android:largeHeap="true"
in your Manifest file under the application tag.
The largeHeap tells the VM to give you more RAM so you can manage big bitmaps and Strings. LargeHeap works in api 12+.
And if you want to catch the error with try/catch block you need to use
try
{
}catch (OutOfMemoryError e) {
// TODO: handle exception
}
If you are experiencing this while building the project in Android Studio
Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
add in your build.gradle file
dexOptions {
javaMaxHeapSize "4g"
}
Solution 2:
You did not catch it. OutOfMemoryError
is derived from Error
, not from Exception
. It is an Error
because normally an application is not supposed to catch it, there is close to nothing your application can do to recover.
Post a Comment for "Java.lang.outofmemoryerror Even In A Try-catch Block?"