Android Question Give me a empty string ?

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi
PC side give me string "#0000011223*". Why I always get a null string(s1) from BytesToString but buffer() have data inside ?

Sub AStream_NewData(buffer() As Byte)
Dim s1 As String

If buffer.Length>0 Then
s1 = BytesToString(buffer, 0, buffer.Length, "UTF8")
bt.Rxbf = bt.Rxbf + s1
End If
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
I have tried this:

B4X:
    Dim s As String = "#0000011223*"
    Dim Buffer() As Byte
    Buffer = s.GetBytes("UTF8")
    Dim S1 As String
    S1 = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Log(S1)

Result:
B4X:
 ** Activity (main) Create, isFirst = true **
#0000011223*
** Activity (main) Resume **

Evidently the data that you get are already corrupt
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
bt.Rxbf = bt.Rxbf + s1 ==> java.lang.NumberFormatException: Invalid double: "" ?????
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi
Why following code is ok !


If buffer.Length>0 Then
s1 = BytesToString(buffer, 0, buffer.Length, "UTF8")

If s1.Length > 0 Then
bt.Rxbf = s1
End If
End If
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Type BtPacket (Cmd As Int, Step As Int, Interval As Int,Txbf As String, Rxbf As String)
Dim bt As BtPacket
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
bt.Rxbf seems to be an double. and you cannot add a string to a double

What you want is concat the both strings. You have to use & instead of +
 
Upvote 0
Top