Bug? error code on B4A 7.0.1

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.

i m testing some codes and i see on B4A 7 Beta #1 i dont have any errors, on B4A non beta i got errors on the code.

this code is to make screenshot and save a image file.


HERE IS THE CODE
Code:
    Try
        Dim Obj1, Obj2 As Reflector
        Dim bmp As Bitmap
        Dim c As Canvas
        Obj1.target = Obj1.GetActivityBA
        Obj1.target = Obj1.GetField("vg")
        bmp.InitializeMutable(Activity.Width, Activity.Height)
        c.Initialize2(bmp)
        Dim args(1) As Object
        Dim types(1) As String
        Obj2.target = c
        Obj2.target = Obj2.GetField("canvas")
        args(0) = Obj2.target
        types(0) = "android.graphics.Canvas"
        Obj1.RunMethod4("draw", args, types)
        Dim out As OutputStream
        out = File.OpenOutput(File.DirInternal, "share.jpg", False)
        bmp.WriteToStream(out, 100, "JPEG")
        out.Close
    Catch
        If LastException.IsInitialized Then Log(LastException)
    End Try

WORKS ON B4A 7 BETA AND DONT WORKS ON B4A NON BETA

THE ERROR LOG IS
(NullPointerException) java.lang.NullPointerException: Attempt to read from field 'java.lang.ref.WeakReference anywheresoftware.b4a.BA$SharedProcessBA.activityBA' on a null object reference

How can i fix this error to work on B4A non beta? lasted version

thx all
 
I've tried it with this code and it works properly:
Code:
Sub Activity_Create(FirstTime As Boolean)
   Dim Obj1, Obj2 As Reflector
   Dim bmp As Bitmap
   Dim c As Canvas
   Obj1.target = Obj1.GetActivityBA
   Obj1.target = Obj1.GetField("vg")
   bmp.InitializeMutable(Activity.Width, Activity.Height)
   c.Initialize2(bmp)
   Dim args(1) As Object
   Dim types(1) As String
   Obj2.target = c
   Obj2.target = Obj2.GetField("canvas")
   args(0) = Obj2.target
   types(0) = "android.graphics.Canvas"
   Obj1.RunMethod4("draw", args, types)
   Dim out As OutputStream
   out = File.OpenOutput(File.DirInternal, "share.jpg", False)
   bmp.WriteToStream(out, 100, "JPEG")
   out.Close
End Sub

Please upload a project that demonstrates this issue.
 
Back
Top