Android Question anywheresoftware.b4a.keywords.Common.CallSub4

D

Deleted member 103

Guest
Hi,

why are these errors triggered?
What can be wrong with my code?

crash_02.PNG

My code looks like this.
Starter-Service:
B4X:
Sub GPS1_GpsStatus (Satellites As List)
    Dim Set As Int = 0
    For i = 0 To Satellites.Size -1
        Dim GPSSat As GPSSatellite
        GPSSat = Satellites.Get(i)       
        If GPSSat.UsedInFix Then Set = Set + 1
    Next
   
    If Not(IsPaused(Main)) Then
        CallSub2(Main, "ShowGpsStatus", Set)
       
    else if Not(IsPaused(mSatellites)) Then
        CallSub2(mSatellites, "GpsStatus", Satellites)
       
    End If
End Sub

Main-Activity:
B4X:
Public Sub ShowGpsStatus (Satellites As Int)
    If Starter.manager.GetString("lstClockSynchModus") = "GPS" Then
        imgGPSStatus.Visible = True
        If Satellites < 3 Then
            imgGPSStatus.Bitmap=LoadBitmap(File.DirAssets,"stat_sys_gps_off.png")
        Else if Satellites < 7 Then
            imgGPSStatus.Bitmap=LoadBitmap(File.DirAssets,"stat_sys_gps_on-50.png")
        Else
            imgGPSStatus.Bitmap=LoadBitmap(File.DirAssets,"stat_sys_gps_on-100.png")
        End If
    End If
End Sub

Activity-mSatellites:
B4X:
Sub GpsStatus (Satellites As List)
    Dim i,set As Int
    Dim txt1, txt2, txt3, txt4, txt5 As String
   
    set=0
    txt1 = "Index"
    txt2 = "Azimuth"
    txt3 = "Elevation"
    txt4 = "Used"
    txt5 = "S / N ratio"
    lblSatellitesNb.Text = "Nb. of satellites: " & Satellites.Size
    lblSatellitesValid.Text = "Valid satellites: " & set
    For i = 0 To Satellites.Size -1
        Dim GPSSat As GPSSatellite
        GPSSat = Satellites.Get(i)
        txt1 = txt1 & CRLF & (i + 1)
        txt2 = txt2 & CRLF & GPSSat.Azimuth
        txt3 = txt3 & CRLF & GPSSat.Elevation
        txt4 = txt4 & CRLF & GPSSat.UsedInFix
        txt5 = txt5 & CRLF & NumberFormat(GPSSat.Snr, 1, 2)
       
        If GPSSat.UsedInFix Then set = set + 1
    Next
    lblSatellitesValid.Text = "Valid satellites: " & set
    lblSatellitesIndex.Text = txt1
    lblSatellitesAzimuth.Text = txt2
    lblSatellitesElevation.Text = txt3
    lblSatellitesUsed.Text = txt4
    lblSatellitesS_N.Text = txt5
End Sub
 
D

Deleted member 103

Guest
What object is Starter.Manager? Does it definitely contain "lstClockSynchModus"
Yes, certainly. ;)
B4X:
'Starter-Service
Sub Service_Create
   ...
   'Settings-Menu
   SetDefaults
End Sub

Sub SetDefaults
    'defaults are only set on the first run.
    ...
    If Not(manager.GetAll.ContainsKey("lstClockSynchModus")) Then manager.SetString("lstClockSynchModus", Language.value("GPS"))   
    ...
End Sub
 
Upvote 0
D

Deleted member 103

Guest
What is line 2592 in the generated Java code?
2592.JPG


Code in Main-Activity:
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 IsExternKeyUp As Boolean = True

    'Objekte für die Atomzeit
    Private Thread1 As Thread
    Private Thread2 As Thread

    Private phone1 As Phone
    Private plyVolume As Double
    Private oldVolume As Int
   
    'Timer für Verzögerungszeit
    Private delaytime As Timer
    Private lgdelaytime As Long

    Private LiteLimitTimer As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
...
  If FirstTime = True Then
     
     LiteLimitTimer.Initialize("LiteLimitTimer", 5 * DateTime.TicksPerMinute)
         
     'Objekte für die Atomzeit
     Thread1.Initialise("Thread1")
     Thread2.Initialise("Thread2")
     
     delaytime.Initialize("delaytime", 1000)

   End If
...
End Sub
 
Upvote 0
D

Deleted member 103

Guest
I guess that the code was changed as it points to a different sub. BTW, why are you using the Threading library? It can be a source to many problems if not used correctly.
I think it's the same mistake as here, but has not caused any problems since then. :(
Now it will be time for me to change something. :)
 
Upvote 0
D

Deleted member 103

Guest
Now I have changed my code, you mean that it is right?
Old Code:
B4X:
#Region Atomzeit
' must be startet in a non-gui background thread
' the undescores prevents the sub name from obfuscation, so Thread1.Start will find this sub even with the compile option "Relaese (obfuscated)"

Sub GetAtomTime
    Dim args(0) As Object
    Thread1.Start(Me, "Get_Current_Time", args)
End Sub

Sub Get_Current_Time
    Dim str() As String = Regex.Split("—", Starter.manager.getString("lstTimeServer"))
    Dim TimeServer As String = str(1).Trim
    '    Log("TimeServer=" & TimeServer)
    sntp.NtpServerName = TimeServer              ' only needed if you don't want to use the default server "0.us.pool.ntp.org"
    sntp.TimeOut = 10000                      ' only needed if you don't want to use the default timeout value of 30000 milliseconds (30 seconds)
    sntpticks = sntp.getGmtNtpTime
End Sub

Sub Thread1_Ended(endedOK As Boolean, error As String) 'The thread has terminated. If endedOK is False error holds the reason for failure
    Dim args(0) As Object
    ' to perfom giu-actions directly after receiving the time
    ' we have to do this with the help of a separate gui-thread
    Log("endedOK=" & endedOK & " ;error=" & error)
    Thread2.RunOnGuiThread("Show_Results", args)
End Sub

Sub Show_Results
    If sntpticks > -1 Then
        Starter.lngTimer = DateTime.Now - sntpticks
        Starter.IsAtomTimeSet = True
    Else
        Starter.lngTimer = 0
        Starter.IsAtomTimeSet = False
    End If
    '    Log("Thread1_Ended: lngTimer=" & lngTimer)
    '    Log("DateTime.Now=" & DateTime.Now)
    '    Log("sntp.getGmtNtpTime=" & sntpticks)
End Sub
#End Region

new code:

B4X:
#Region Atomzeit
' must be startet in a non-gui background thread
' the undescores prevents the sub name from obfuscation, so Thread1.Start will find this sub even with the compile option "Relaese (obfuscated)"

Sub GetAtomTime
    Thread1.Start(Me, "Get_Current_Time", null)
End Sub

Sub Get_Current_Time
    Dim str() As String = Regex.Split("—", Starter.manager.getString("lstTimeServer"))
    Dim TimeServer As String = str(1).Trim
    '    Log("TimeServer=" & TimeServer)
    sntp.NtpServerName = TimeServer              ' only needed if you don't want to use the default server "0.us.pool.ntp.org"
    sntp.TimeOut = 10000                      ' only needed if you don't want to use the default timeout value of 30000 milliseconds (30 seconds)
    sntpticks = sntp.getGmtNtpTime
End Sub

Sub Thread1_Ended(endedOK As Boolean, error As String) 'The thread has terminated. If endedOK is False error holds the reason for failure
    ' to perfom giu-actions directly after receiving the time
    ' we have to do this with the help of a separate gui-thread
    Log("endedOK=" & endedOK & " ;error=" & error)
    Thread2.RunOnGuiThread("Show_Results", null)
End Sub

Sub Show_Results
    If sntpticks > -1 Then
        Starter.lngTimer = DateTime.Now - sntpticks
        Starter.IsAtomTimeSet = True
    Else
        Starter.lngTimer = 0
        Starter.IsAtomTimeSet = False
    End If
    '    Log("Thread1_Ended: lngTimer=" & lngTimer)
    '    Log("DateTime.Now=" & DateTime.Now)
    '    Log("sntp.getGmtNtpTime=" & sntpticks)
End Sub
#End Region
 
Upvote 0
Top