Android Question For Each do not work

3394509365

Active Member
Licensed User
Longtime User
i receive this Packet "Quality:GOOD Level:250" from UDP

i have the following message and the for each does not work

B4X: Copy
HiTouch restricted: AboardArea.
EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
  HWUI Binary is  enabled
Error occurred on line: 102 (Main)
java.lang.RuntimeException: Method: getSize not found in: java.lang.String
    at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:985)
    at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:644)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:731)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7529)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:203)
    at java.net.SocketInputStream.read(SocketInputStream.java:139)

This is my code

B4X: Copy
Sub UdpSEvent_PacketArrived (Packet As UDPPacket)

    Dim StringaArrivata As String=BytesToString(Packet.Data, Packet.Offset, Packet.Length, "ASCII")


    For Each line As String In StringaArrivata         ' in this line i have the error

        Dim s() As String = Regex.Split(":", line)
      
        Dim Qualità As String = s(0).Trim

        Dim Livello As String = s(1).Trim

    Next
  

    EditTextReceiver.Text = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "ASCII")

     

End Sub


I would like this result

Quality:GOOD
Level:250

if the problem is in the string that arrives you can change it, in the arduino code
 
in addition to what j. cameron said,
if you're saying that "Quality:GOOD Level:250" is always what the return looks like, then you could split on " "
B4X: Copy
   dim part(2) as string = regex.split(" ", string)
   log( part(0) )
   log( part(1) )

in other words, if a single space separates the 2 parts, you split on it.
if, later, you wanted to separate "Quality" from "GOOD", you split on ":"
B4X: Copy
   for each p as string in part
      dim littlepart(2) as string = regext.split(":", p)
      log( littlepart(0) )
      log( littlepart(1) )
   next

then you can use for each/in and everybody happy ;)
 
Upvote 0
Back
Top