B4J Question (NumberFormatException) error

hakha4

Member
Licensed User
Longtime User
Hi
Sending strings to a RF-Link on an Arduino Mega from a B4J program. Works ok but get strange serial error :
Sending 10;NewKaku;0129abf6;10;OFF from MLS --> Serial OK

But when sending :
Sending 10;NewKaku;0129abf6;f;ON to Serial FAILED

(NumberFormatException) java.lang.NumberFormatException: For input string: "e"

Why is not both '10' and 'e' considered to be a string in serial ?

B4X:
'###################################################################################
'########### Send commands from MLServer to Serial(RF) OR Gateway ##################
'###################################################################################
Sub TcpStreams_NewText(Text As String)'data from MLS (port 20000)
     
    'split cmd
    Dim A() As String = Regex.Split(";", s.Mid(Text,2,s.Len(Text)-1))'remove $
    Log(A(1) & " " & A(2) & " " & A(3) & " " & A(4))
    'update LOG
    Ser_text.Text = Ser_text.Text & Text & Chr(13) & Chr(10)
    ' Ser_text.ScrollTopPosition = Ser_text.Text.Length
    Ser_text.SetSelection(Ser_text.Text.Length, Ser_text.Text.Length)
    'CHECK If COMMND To BE RUN ON GATEWAY OR TO BE SENT TO SERIAL
    Select Case s.mid(Text,1,1)
        Case "#" ' cmd from MLS not to be sent to serial
            Log("MLS -->  Gateway")
         
            eval_MLSCMD(s.Mid(Text,2,s.Len(Text)-1))
        Case Else
           
            Try
                update_switchStatus(A(1),A(2),A(3),A(4),"","")
                ast.Write (s.Trim(Text) & Chr(13) & Chr(10))
 
                Log("Sending " & Text & " from MLS --> Serial OK")
                Log("Updating_switchStatus")
            '    update_switchStatus(A(1),A(2),A(3),A(4),"","")
            Catch
                Log("Sending " & Text & " to Serial FAILED")
               
                Log(LastException)
            End Try
   
    End Select
End Sub

Any help appreciated
Regards Håkan
 

DonManfred

Expert
Licensed User
Longtime User
'split cmd
Dim A() As String = Regex.Split(";", s.Mid(Text,2,s.Len(Text)-1))'remove $
Which $ are you removing? Based on the code you are sending there is no $ sign....
 
Upvote 0

hakha4

Member
Licensed User
Longtime User
Sorry,misleading old code that will be changed when sending to serial works ok. The string that is send to serial is in format like 10;NewKaku;0129abf6;f;ON.

The issue is why for example 10;NewKaku;0129abf6;10;ON sends ok and
10;NewKaku;0129abf6;e;ON fails.. Both are declared as strings but for some reason the latter gives error
(NumberFormatException) java.lang.NumberFormatException: For input string: "e".

If I understand error correct the '10' is interpreted as number and 'e' is not despite being a part of a string ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You should provide more information. For example what does
update_switchStatus

do? Sounds like it is handling the values as numbers. e is not a Number

You can also provide a fully example which shoes the problem. Export as zip and upload the zip.

Also you could provide the full stacktrace and the line which causes the error.... Hard to help with this less info
 
Upvote 0

hakha4

Member
Licensed User
Longtime User
Thank's for reply. The problem was gone when skipping the update_switchStatus sub and rewrite the code. Still mysterious though since all call's was declared as 'string' !
BTW I thought that when an error was raised in one module the problem's lies there. Even if another sub is called why should a local variable be changed ? Much more to learn!
Regards Håkan
 
Upvote 0
Top