I copied exactly a code to create a canvas rect and put a text inside it... And error ocurred and i don't know why...
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Dim Canvas1 As Canvas
Dim Rect1 As Rect
Dim width,height As Float
Dim t As String
t="Text to write"
width = Canvas1.MeasureStringWidth(t,Typeface.DEFAULT,14) ---> Here crashes !!!
height= Canvas1.MeasureStringHeight(t,Typeface.DEFAULT,14)
Rect1.Initialize(100dip, 100dip, 100dip + width,100dip + height)
Canvas1.DrawRect(Rect1,Colors.White,True,0)
Canvas1.DrawText(t,Rect1.Left,Rect1.Bottom,Typeface.DEFAULT,14,Colors.Blue,"LEFT")
End Sub
The error i get is this one:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 45 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Xfermode android.graphics.Paint.setXfermode(android.graphics.Xfermode)' on a null object reference
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.checkAndSetTransparent(CanvasWrapper.java:90)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.DrawRect(CanvasWrapper.java:186)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:748)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Thank You !!!
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Dim Canvas1 As Canvas
Dim Rect1 As Rect
Dim width,height As Float
Dim t As String
t="Text to write"
width = Canvas1.MeasureStringWidth(t,Typeface.DEFAULT,14) ---> Here crashes !!!
height= Canvas1.MeasureStringHeight(t,Typeface.DEFAULT,14)
Rect1.Initialize(100dip, 100dip, 100dip + width,100dip + height)
Canvas1.DrawRect(Rect1,Colors.White,True,0)
Canvas1.DrawText(t,Rect1.Left,Rect1.Bottom,Typeface.DEFAULT,14,Colors.Blue,"LEFT")
End Sub
The error i get is this one:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 45 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Xfermode android.graphics.Paint.setXfermode(android.graphics.Xfermode)' on a null object reference
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.checkAndSetTransparent(CanvasWrapper.java:90)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.DrawRect(CanvasWrapper.java:186)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:748)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Thank You !!!
Last edited: