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

前端 未结 30 2177
暗喜
暗喜 2020-11-21 07:33

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

30条回答
  •  Happy的楠姐
    2020-11-21 07:43

    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.

    
    

    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.

提交回复
热议问题