Android Question B4XProgressBar java.lang.NullPointerException

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Trying out this class:

https://www.b4x.com/android/forum/threads/b4x-xui-b4xprogressbar.90826/

I am using the unaltered class and use it like this from Main:

B4X:
Sub TestProgressBar
 Dim i As Int
 pnlFindPat.LoadLayout("progressbar")
 ProgressBar1.Initialize("Main", "B4XProgressBar1")
 For i = 0 To 100
  ProgressBar1.Progress = i
  Sleep(100)
 Next
End Sub

All is fine up to the ProgressBar1.Progress = i (the progressbar shows in the panel) and then gives me the mentioned error in this code in the class:

B4X:
Private Sub DrawValue(Value As Float)
 Log("DrawValue, cvs.TargetView.Tag: " & cvs.TargetView.Tag) 'this is fine
 Log("DrawValue, cvs.TargetRect.Width: " & cvs.TargetRect.Width) 'this is fine
 cvs.ClearRect(cvs.TargetRect)  '<<<<<< error here: java.lang.NullPointerException: null receiver
 If vertical Then
  cvs.DrawLine(cvs.TargetRect.CenterX, 0, cvs.TargetRect.CenterX, cvs.TargetRect.Bottom, bcolor, thickness)
  cvs.DrawLine(cvs.TargetRect.CenterX, 0, cvs.TargetRect.CenterX,  Value / 100 * cvs.TargetRect.Bottom, pcolor, thickness)
 Else
  cvs.DrawLine(0, cvs.TargetRect.CenterY, cvs.TargetRect.Right, cvs.TargetRect.CenterY, bcolor, thickness)
  cvs.DrawLine(0, cvs.TargetRect.CenterY, Value / 100 * cvs.TargetRect.Right, cvs.TargetRect.CenterY, pcolor, thickness)
 End If
 cvs.Invalidate
End Sub

The posted example (in the above URL) works fine.

Any idea what could be the problem here?

RBS
 
Top