Skip to content Skip to sidebar Skip to footer

Android Createbitmap Nullpointerexception

I got a java.lang.NullPointerException when I try to call createBitmap. Here is my code: board = Bitmap.createBitmap(handler.signs.length * cellSize, handler.signs[0].leng

Solution 1:

I traced several intermittent errors where Bitmap.createBitmap() returned null; they happened mostly in Chinese Android phones. The parameters being passed were ok, but I found that the jvm was very low on memory whenever this occurs.

My theory is there are cases where createBitmap() runs out of memory and returns null instead of throwing OutOfMemoryException (which is what it usually does).

My "fix" is to check if createBitmap() returns null and throw our own OutOfMemoryException so it is correctly categorized. Then our error logging treats it as a device issue rather than a functional bug.

Solution 2:

Try use createScaledBitmap instead, I face the same problem before, the reason i remember is the width or the height you want for the bitmap exceeds the size of the device.

Hope this will help you.

Post a Comment for "Android Createbitmap Nullpointerexception"