Android Question timer problem

John Decowski

Member
Licensed User
Im getting this error upon activating my timer no idea why. Ive used timers in the past and havent go this code before?
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim slidedown As Timer
    slidedown.Initialize("SlideDown1" ,1000)
    slidedown.Enabled = False
    Dim Slidertop As Long
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private pnlSlide As Panel
    Private imgTradeBuddyLogo2 As ImageView
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("tbmain")
    pnlSlide.Top = ((pnlSlide.Height * -1) + (imgTradeBuddyLogo2.Height) ) + 5dip
    Slidertop = pnlSlide.top
    imgTradeBuddyLogo2.top = pnlSlide.height - imgTradeBuddyLogo2.height' this adds it up and multiplys by neg 1 to turn number negative
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SlideDown1_tick
    If pnlSlide.Top > = 1 Then
        slidedown.Enabled = False
    Else
        pnlSlide.Top = pnlSlide.Top + 10
    End If
End Sub

Sub imgTradeBuddylogo1_Click
    'slidedown.Enabled = True
End Sub

Sub imgTradeBuddyLogo2_Click
    slidedown.Interval = 10
    slidedown.Enabled = True
End Sub
Error code:

Logger connected to: samsung SM-N960U
--------- beginning of crash
--------- beginning of main
Copying updated assets files (33)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean anywheresoftware.b4a.BA.isActivityPaused()' on a null object reference
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:104)
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)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **


thanks in advance
 

MarkusR

Well-Known Member
Licensed User
u need to move this into activity create.
(b4a 9.3 wrote a info at mouse over.)
B4X:
slidedown.Initialize("SlideDown1" ,1000)
slidedown.Enabled = False
u can also use breakpoints or log(..)
 

Erel

Administrator
Staff member
Licensed User
You should never write code in Process_Globals. Don't ignore the warnings...
 
Top