Android Question Error on Custom view with a timer

Marion Opperman

Member
Licensed User
Longtime User
I have a class that draws an overlay which pops up if the user is inactive for too long. The problem is i get the following error when the timer ticks to change the time in the countdown label.
java.lang.NullPointerException: null receiver
at java.lang.reflect.Field.get(Native Method)
at java.lang.reflect.Field.get(Field.java:279)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSubHelper(Shell.java:507)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:490)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:402)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

Here is the whole class:
B4X:
Sub Class_Globals
    Dim countdown As Timer
    Dim overlayPanel As Panel
    Dim timeoutL1 As Label
    Dim timeoutL2 As Label
    Dim timeoutB2 As Button
    Dim icounter As Int = 5
    Dim m As String
    Dim e As String       
    Dim bd As ColorDrawable
End Sub

Sub getOverlayPanel As Panel
   Return overlayPanel
End Sub

Sub setOverlayPanel(s As Panel)
   overlayPanel = s
End Sub

Public Sub Initialize (Module As String, Event As String, act As Object)
    e = Event
    m = Module
    DrawUI
End Sub

Sub DrawUI
    Dim BoldSans As Typeface
    BoldSans = Typeface.CreateNew(Typeface.SANS_SERIF, Typeface.STYLE_BOLD)
    Dim ItalSans As Typeface
    ItalSans = Typeface.CreateNew(Typeface.SANS_SERIF, Typeface.STYLE_ITALIC)
    overlayPanel.Initialize("overlayPanel")
    Dim cd As ColorDrawable
    cd.Initialize(Colors.RGB(242,157,4),0)
    Dim txtSize As Int = 20 * ((100%x + 100%y) / (320dip + 480dip))
    Dim lblHeight As Int = DipToCurrent(txtSize) + txtSize   
    Dim lblHeight As Int
    lblHeight = DipToCurrent(txtSize) + 2dip   
    Dim barHeight As Int = (lblHeight * 2) + 16dip
    bd.Initialize2(Colors.RGB(242,157,4),((barHeight-6dip)/2),3dip, Colors.White)
   
    overlayPanel.Color = Colors.ARGB(120,105,105,105) 'Partially transparent
       
    timeoutL1.Initialize("")
    timeoutL1.Background = cd
    timeoutL1.Textsize = txtSize
    timeoutL1.TextColor = Colors.White
    timeoutL1.Text = " Are you still there?"
    timeoutL1.Typeface = BoldSans
    timeoutL1.Gravity = Gravity.TOP
    timeoutL1.SendToBack
       
    timeoutL2.Initialize("")
    timeoutL2.Background = cd
    timeoutL2.Textsize = 17 * ((100%x + 100%y) / (320dip + 480dip))
    timeoutL2.Typeface = ItalSans
    timeoutL2.TextColor = Colors.White
    timeoutL2.Gravity = Gravity.LEFT
    timeoutL2.Text = " Logging out in 120 seconds"
   
    timeoutB2.Initialize("b2")
    timeoutB2.Background = bd
    timeoutB2.Textsize = 16 * ((100%x + 100%y) / (320dip + 480dip))
    timeoutB2.TextColor = Colors.White
    timeoutB2.Text = "OK"
    
    overlayPanel.AddView(timeoutL1,0,50%y-(barHeight/2),100%x,barHeight)
    overlayPanel.AddView(timeoutL2, 0,50%y + 1dip,100%x, lblHeight)
    overlayPanel.AddView(timeoutB2,100%x - barHeight +5dip, 50%y-(barHeight/2) +5dip, barHeight-10dip, barHeight-10dip)

    countdown.Initialize("countdown", 1000)
    countdown.Enabled = True
   
End Sub

Sub overlayPanel_Click As Boolean
    Return False
End Sub

Sub countdown_Tick
    icounter = icounter - 1   
    If icounter > 0 Then
    timeoutL2.Text = " Logging out in " & icounter & " seconds"
    Else
        countdown.Enabled = False
        CallSub2(m, "log_Out", "inactivity")
    End If
End Sub

Sub b2_Click   
    countdown.Enabled = False
    CallSub(m,e)
End Sub
 
Top