Relate Java line to B4A line in error

jpvniekerk

Active Member
Licensed User
Longtime User
I have a program out in beta testing. One of the testers get an error consistently. Since he is far away, I cannot do a debug on his unit (or can I? How?)

All I get is this: “An error has occurred in sub: main-gps-location changed (java line: 2395) java.Lang.number format exception”. I have looked at every line in that sub but cannot find where a number format exception can be.
Is there a way to relate the java line back to the B4A program line to help me get a better idea of where the problem lies?
Funny thing is, I run the debug on my phone and every line process fine - no errors.

Here is the code from the sub:
B4X:
Sub GPS_LocationChanged (Location1 As Location)
   Dim Lat As Double
   Dim Lon As Double
        Lat = Location1.Latitude
   Lon = Location1.Longitude
   Dim LatDegText,LonDegText As String
   Dim LatDeg,LatMin,LonDeg,LonMin As String
   Dim PentadLat,PentadLon As String
   Dim PentadTempTxt As String
   
   LatDegText = Location1.ConvertToSeconds(Location1.Latitude)
   LonDegText = Location1.ConvertToSeconds(Location1.Longitude)
   
   LatDeg = LatDegText.SubString2(1,3)
   LonDeg = LonDegText.SubString2(0,2)
   LatMin = LatDegText.SubString2(4,6)
   LonMin = LonDegText.SubString2(3,5)
   PentadLat = LatDeg & LatMin.SubString2(0,1)

   If LatMin.SubString2(1,2) < 5 Then
      PentadLat = PentadLat & "0"
   Else
      PentadLat = PentadLat & "5"
   End If
   PentadLon = LonDeg & LonMin.SubString2(0,1)
   If LonMin.SubString2(1,2) < 5 Then
      PentadLon = PentadLon & "0"
   Else
      PentadLon = PentadLon & "5"
   End If   
   PentadTempTxt = PentadLat &"_"&PentadLon
   CurrentPentad = PentadTempTxt
   
   GpsLblLatDec.Text = NumberFormat2(Location1.Latitude,0,6,6,False)
   GpsLblLatDms.Text = Location1.ConvertToSeconds(Location1.Latitude)
   GpsLblLonDec.Text = NumberFormat2(Location1.Longitude,0,6,6,False)
   GpsLblLonDms.Text = Location1.ConvertToSeconds(Location1.Longitude)
   GpsLblAlt.Text = NumberFormat2(Location1.Altitude,0,0,0,False)
   GpsLblAcc.Text = Location1.Accuracy
   GpsLblPentad.Text = PentadTempTxt
'   Dim GpsLblSat As Label
   
   If InPentad = True Then
      If CurrentPentad <> SelectedPentad Then
         PlayDingDong = SP.Play(LoadDingDong,1,1,1,0,1.5)
         Msgbox("YOU HAVE LEFT THE SELECTED PENTAD. STOP MAPPING TO KEEP ACCURATE TIMING","W A R N I N G")
         InPentad = False
      End If
   Else 'Out of Pentad
      If CurrentPentad = SelectedPentad Then
         PlayDingDong = SP.Play(LoadDingDong,1,1,1,0,1.5)
         Msgbox("YOU HAVE ENTERED THE SELECTED PENTAD. START MAPPING TO KEEP ACCURATE TIMING","W A R N I N G")
         InPentad = True
      End If   
   End If   
   
      
End Sub

Any advice or help will be GREATLY appreciated

Johannes
 

Inman

Well-Known Member
Licensed User
Longtime User
You need to compile the app in Debug mode (select Debug in the white dropdown box located at the top-middle part of the screen). Now since your tester doesn't have B4A, there will be a startup delay of about 5 seconds for the app (showing "Waiting for debugger" message). After that the app will continue normally. And now all the error messages will have B4A line numbers instead of java.
 
Upvote 0

jpvniekerk

Active Member
Licensed User
Longtime User
Thanks all for your help - I think I am on the track now

The error is on this line:
B4X:
       PentadLon = PentadLon & "0"

Both variables are defined as strings - this does not make any sense - or does it???

In the line just before, I am comparing a string character with an integer:
B4X:
     If LatMin.SubString2(1,2) < 5 Then

LatMin contains only numeric characters (0 through 9). Can this be the problem?
 
Upvote 0

jpvniekerk

Active Member
Licensed User
Longtime User
Margret,
Latmin is only two characters long ("23"). But I'm using substring2 and this does not give me an error.
I'm still confused :confused:
PentadLon before this line is "203"
 
Upvote 0

jpvniekerk

Active Member
Licensed User
Longtime User
I think I found the problem -and why it occurs only intermittently!


B4X:
   LatDegText = Location1.ConvertToSeconds(Location1.Latitude)

ConvertToSeconds throws away leading zeros!!! (am I correct)

Sometime LatDegText would look like this: "24:35:42,1234"
And at other times like this: "24:7:25,1234" when I expected ""24:07:25,1234"

So my algorithm of finding the substring based on character position is faulty.

Is there a better way to extract the Degrees and Minutes separately, or is there a way to fromat ConvertToSeconds to retain leading zeros? The latter would be preferred.

Thanks
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You can use
B4X:
regex.split
in order to get the desired pieces of the latDegText.
 
Upvote 0

jpvniekerk

Active Member
Licensed User
Longtime User
Thanks mc73.

I'm a noob and have never user regex.split. Can you give me an example of how to do this (or tell me where I can find more info on it)?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Sure. You can try this:
B4X:
Dim tempArray()
tempArray=Regex.Split(":",LatDegText)
'now you can get the piece you want. For e.g. if you want the second part, get tempArray(1) and so on
 
Upvote 0
Top