Android Question Bitmap mystery - setHasAlpha crash

wimpie3

Well-Known Member
Licensed User
Longtime User
Following function crashes with java.lang.reflect.InvocationTargetException / Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.setHasAlpha(boolean)' on a null object reference

B4X:
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, keepRatio As Boolean, filter As Boolean) As Bitmap
    Dim jo As JavaObject
    Dim newHeight As Int
    newHeight = Height
    If keepRatio Then
        Dim CalcRatio As Int
        CalcRatio = Original.Width / Original.Height
        newHeight = Width / CalcRatio
    End If
    jo.InitializeStatic("android.graphics.Bitmap")
    Log(Original)
    Return jo.RunMethod("createScaledBitmap", Array (Original, Width, newHeight, filter))
End Sub

FYI, the bitmap passed in the function is valid, the log shows "(Bitmap): 1080 x 1920"...
 

JordiCP

Expert
Licensed User
Longtime User
Yes. But the setHasAlpha you are refering to, was made public in api 12, according to some posts I have read.

Just to try, compile for a higher level to see if it works
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
That's not an option. I need to rescale a bitmap in API 10. Seems rather strange this wouldn't be possible on lower API's?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
According to the documentation it is possible since API 1. I was refering to the "setHasALpha" which exists since API 12. But possibly it is being used internally so it existed.

Even if you need API10, I would recompile for a higher API to see if THIS is the problem.

Also, do you mean you want to rescale in API 10 or that the app should be compatible with API 10? If so, just try with minSDKversion to 10, but targetSDK to a higher one.
 
Upvote 0
Top