Android Question Crashes and crashes again ...

Status
Not open for further replies.
D

Deleted member 103

Guest
Hi,

It does not matter how many crashes I fix, there are always new ones.
Above all, the error "gpstimer_tick" makes me crazy, which is actually quite something simple. In this timer the time is displayed in a label.

B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now   
    lblClock.Text = DateTime.time(time)
End Sub

The same error I have in 2 other app too.
I almost suspect that the error is in the function "DateTime".

Programming is no fun anymore.
I do not feel like it anymore. :(

error.PNG
 

Peter Simpson

Expert
Licensed User
Longtime User
Is gpstimer_tick in a service or activity?

Nothing to do with your crashes, but why don't you change
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now
    lblClock.Text = DateTime.time(time)
End Sub
To
B4X:
Sub GpsTimer_Tick
    lblClock.Text = DateTime.Time(DateTime.Now)
End Sub
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Hi,

It does not matter how many crashes I fix, there are always new ones.
Above all, the error "gpstimer_tick" makes me crazy, which is actually quite something simple. In this timer the time is displayed in a label.

B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now
    lblClock.Text = DateTime.time(time)
End Sub

The same error I have in 2 other app too.
I almost suspect that the error is in the function "DateTime".

Programming is no fun anymore.
I do not feel like it anymore. :(

View attachment 63751
From the crash report I see errors of different types and on many different divers.

In what you are referring to, I read:
java.lang.NullPointerException
in fg.speed_pilot.lite main.gpstimer_tick

and the question arises ... is it possible that at some point lblClock does not point to anything?
Is the UI somehow closed?

try:
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now 
    Try
        lblClock.Text = DateTime.time(time)
    Catch
        Log(LastException.IsInitialized)
    End Try
End Sub
or
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now  
   
    If lblClock.IsInitialized Then
       lblClock.Text = DateTime.time(time)
    Else
        Log("Error: Not initialized")
    End If
End Sub
 
Last edited:
Upvote 0
D

Deleted member 103

Guest
1) The timer is in the main activity
2) In Activity_pause the timer is deactivated
3) in Activity_resume the timer is activated
4) the label "lblClock" is initialized in the designer
So I see tehoretically no mistake.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Another guess: even if you disable the timer, a tick event is already queued and it is executed later.

If this is the case, I would protect it with a global flag in Process_globals that will allow to check if the timer is really enabled when the event is called. It could be mixed with Star-Dust and Peter Simpson's suggestions, to make it more robust and cleaner

B4X:
Sub Process_Globals
   Dim really_enabled as Boolean = False
End Sub

Sub Activity_Pause
   really_enabled=False
   GpsTimer.Enabled = False     '<-- At this moment perhaps there is already a missing event.
   ...
End Sub

Sub Activity_Resume
   GpsTimer.Enabled = True
   really_enabled = True
End Sub

Sub GpsTimer_Tick
    if Not(really_enabled) Then return     ' This will avoid annoying previously stacked events
    If lblClock.IsInitialized Then              ' Good practice
       lblClock.Text = DateTime.time(DateTime.now)   'Peter Simpson dixit!
    Else
        Log("Error: Not initialized")
    End If
End Sub
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Another guess: even if you disable the timer, a tick event is already queued and it is executed later.

I had no idea that was even possible, queued for later execution after enable = False. That has opened my eyes a bit wider as that would never have crossed my mind.

Thank you...
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I had no idea that was even possible, queued for later execution after enable = False.
Well, the reason why you had no idea that it was possible is because.... my statement is probably incorrect :rolleyes:!!! sorry about that --> I've tried to reproduce it, because that's how I really thought that timers worked: in my mind, they would fire internally exactly when scheduled, and if a non-interruptible (by means of DoEvents or Sleep(0)) Sub was being executed at that moment, the event would have to wait until the Sub finished. This is still true, but I thought that "the way to perform this wait" was just to queue it and wouldn't be affected by later disabling the timer. It may still be doing so (queuing), but I guess that before being executed, there is a check to see if the caller is still enabled...or the events are de-queued when it is disabled.

So, a better conspiracy theory will be needed to explain the issue ;)
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
So, a better conspiracy theory will be needed to explain the issue ;)

So you was thinking that it might work a bit like StartServiceAt but with an activity. So anything could be happening in between the last second and the next second and that includes an activity pausing?

Good theory I suppose :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, nothing useful can be produced from a thread such as this one.

If you want to get help with a crash report then you should create a thread, with an informative title, with the stack trace and relevant code. A thread such as this is just a rant, mostly about your own code which we are not familiar with.
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
I once had a weird nullpointer issue where things where not initialized fast enough or something.

I then used this method to bypass it...

B4X:
Sub GpsTimer_Tick
 if lblClock.isInitialized then lblClock.Text = DateTime.Time(DateTime.Now)
End Sub

Might not be related to this tho.

Maybe you start your timer too soon?

without full code we can only guess.
 
Upvote 0
D

Deleted member 103

Guest
Might not be related to this tho.

Maybe you start your timer too soon?
Hi @sorex ,

I do not think that's basically my code:
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

   Private GpsTimer As Timer
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 lblClock As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("frmMain")

   If FirstTime = True Then
       GpsTimer.Initialize("GpsTimer", 100)
   End If
   
   '...
End Sub

Sub Activity_Resume
   GpsTimer.Enabled = True
   '...   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   GpsTimer.Enabled = False
   '...
End Sub

But I have to say that none of my 5 Android devices caused a crash.
 
Upvote 0
Status
Not open for further replies.
Top