This is the full error log:
Error occurred on line: 102 (B4XProgressBar)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.RectF.round(android.graphics.Rect)' on a null object reference
at anywheresoftware.b4a.objects.B4XCanvas$B4XRect.toRect(B4XCanvas.java:164)
at anywheresoftware.b4a.objects.B4XCanvas.ClearRect(B4XCanvas.java:93)
at b4a.sqlitelight1.b4xprogressbar._drawvalue(b4xprogressbar.java:250)
at b4a.sqlitelight1.b4xprogressbar._setprogress(b4xprogressbar.java:84)
at b4a.sqlitelight1.main$ResumableSub_TestProgressBar.resume(main.java:8636)
at b4a.sqlitelight1.main._testprogressbar(main.java:8605)
at b4a.sqlitelight1.main._actionbar_menuitemclick(main.java:1466)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$1.run(BA.java:335)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Line 102 is this in
Private Sub
DrawValue(Value As Float)
I added some logs to the class and can see that somewhere the passed customview (the progressbar) becomes un-initialized:
B4XProgressBar, Initialize
1 DesignerCreateView, mBase.IsInitialized: true
2 DesignerCreateView, mBase.IsInitialized: true
3 DesignerCreateView, mBase.IsInitialized: true
1 DrawValue, mBase.IsInitialized: true
2 DrawValue, mBase.IsInitialized: true
4 DesignerCreateView, mBase.IsInitialized: true
B4XProgressBar, DesignerCreateView
1 setProgress, mBase.IsInitialized: false
I simplified the class a bit, but get same error with the original code:
#DesignerProperty: Key: BackgroundColor, DisplayName: Background Color, FieldType: Color, DefaultValue: 0xFF757575, Description:
#DesignerProperty: Key: ProgressColor, DisplayName: Progress Color, FieldType: Color, DefaultValue: 0xFF38B8FF, Description:
#DesignerProperty: Key: Thickness, DisplayName: Thickness, FieldType: Int, DefaultValue: 5, Description:
#DesignerProperty: Key: Orientation, DisplayName: List Orientation, FieldType: String, DefaultValue: Horizontal, List: Vertical|Horizontal
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Private mBase As B4XView 'ignore
Private xui As XUI 'ignore
Private bcolor, pcolor As Int
Private thickness As Float
Private cvs As B4XCanvas
Private oRect As B4XRect
Private vertical As Boolean
Private currentValue As Float
Private DurationFromZeroTo100 As Int = 500
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
Log("B4XProgressBar, Initialize")
End Sub
'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
mBase = Base
Log("1 DesignerCreateView, mBase.IsInitialized: " & mBase.IsInitialized)
bcolor = xui.PaintOrColorToColor(Props.Get("BackgroundColor"))
pcolor = xui.PaintOrColorToColor(Props.Get("ProgressColor"))
thickness = DipToCurrent(Props.Get("Thickness"))
vertical = Props.Get("Orientation") = "Vertical"
cvs.Initialize(mBase)
Log("2 DesignerCreateView, mBase.IsInitialized: " & mBase.IsInitialized)
oRect = cvs.TargetRect
Log("3 DesignerCreateView, mBase.IsInitialized: " & mBase.IsInitialized)
Base_Resize(mBase.Width, mBase.Height)
Log("4 DesignerCreateView, mBase.IsInitialized: " & mBase.IsInitialized)
Log("B4XProgressBar, DesignerCreateView")
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
cvs.Resize(Width, Height)
'AnimateValueTo(currentValue)
DrawValue(currentValue)
End Sub
Public Sub getProgress As Float
Return currentValue
End Sub
Public Sub setProgress(v As Float)
'AnimateValueTo(v)
Log("1 setProgress, mBase.IsInitialized: " & mBase.IsInitialized)
DrawValue(v)
Log("2 setProgress, mBase.IsInitialized: " & mBase.IsInitialized)
End Sub
Private Sub DrawValue(Value As Float)
cvs.ClearRect(oRect) 'error here: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Rect 'anywheresoftware.b4a.objects.B4XCanvas$B4XRect.toRect()' on a null object reference
Log("2 DrawValue, mBase.IsInitialized: " & mBase.IsInitialized)
If vertical Then
cvs.DrawLine(oRect.CenterX, 0, oRect.CenterX, oRect.Bottom, bcolor, thickness)
cvs.DrawLine(oRect.CenterX, 0, oRect.CenterX, Value / 100 * oRect.Bottom, pcolor, thickness)
Else
cvs.DrawLine(0, oRect.CenterY, oRect.Right, oRect.CenterY, bcolor, thickness)
cvs.DrawLine(0, oRect.CenterY, Value / 100 * oRect.Right, oRect.CenterY, pcolor, thickness)
End If
cvs.Invalidate
End Sub
This is the calling code from Main:
Sub TestProgressBar
Dim i As Int
pnlFindPat.LoadLayout("ProgressBar")
ProgressBar1.Progress = 100
For i = 1 To 100
ProgressBar1.Progress = i
Sleep(100)
Next
End Sub
RBS