Alhootti
Active Member
why this error appeared:
im using this code:
B4X:
b4xmainpage_serial_dataavailable (java line: 196)
java.lang.StringIndexOutOfBoundsException: length=0; index=2
at java.lang.String.substring(String.java:2060)
at b4a.a3tvmanager3.b4xmainpage._serial_dataavailable(b4xmainpage.java:196)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
B4X:
Private Sub serial_DataAvailable (Buffer() As Byte)
ReadData = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
If ReadData.StartsWith("$GNZDA") Then
Dim parts() As String = Regex.Split(",", ReadData)
Dim Time As String = parts(1)
Dim hours As String = Time.SubString2(0, 2)' + 04
Dim minutes As String = Time.SubString2(2, 4)
Dim seconds As String = Time.SubString2(4, 6)
Dim DateGPS As String = parts(2)
Dim DayGPS As String = DateGPS.SubString2(0, 2)
Dim DateGPS2 As String = parts(3)
Dim MonthGPS As String = DateGPS2.SubString2(0, 2)
Dim DateGPS3 As String = parts(4)
Dim YearGPS As String = DateGPS3.SubString2(0, 4)
' Label2.Text = DayGPS & "/" & MonthGPS & "/" & YearGPS
Dim ConvertedTime As Long = DateUtils.SetDateAndTime2(YearGPS, MonthGPS, DayGPS, hours, minutes, seconds, 0)
DateTime.TimeFormat = "hh:mm:ss"
Label1.Text = (DateTime.Time(ConvertedTime))' & " " & DateTime.time(MyDate))
' Label1.Text = hours & ":" & minutes & ":" & seconds
End If
End Sub