Android Question java.lang.RuntimeException: JSON Object expected.

Declan

Well-Known Member
Licensed User
Longtime User
Running the WebSocketExample, I get the following error:
B4X:
LogCat connected to: 0123456789ABCDEF
--------- beginning of main
--------- beginning of system
Copying updated assets files (1)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
TextMessage Error: (RuntimeException) java.lang.RuntimeException: JSON Object expected.
TextMessage Error: (RuntimeException) java.lang.RuntimeException: JSON Object expected.
Error occurred on line: 40 (WebSocketHandler)
java.lang.RuntimeException: JSON Object expected.
    at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:50)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.WebSocketWrapper$1.onTextMessage(WebSocketWrapper.java:77)
    at de.tavendo.autobahn.WebSocketConnection$2.handleMessage(WebSocketConnection.java:392)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
TextMessage Error: (Exception) java.lang.Exception:  java.lang.RuntimeException: JSON Object expected.

My device connects fine and I can send messages to the Server.
The error occurs when I send from the server to the device running WebSocketExample.
 

Declan

Well-Known Member
Licensed User
Longtime User
The server is setup to Echo back.
The Log is:
B4X:
LogCat connected to: 0123456789ABCDEF
--------- beginning of main
--------- beginning of system
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
msg: Echo: {"type":"event","event":"Device_Message","params":{"message":"hello"}}
TextMessage Error: (RuntimeException) java.lang.RuntimeException: JSON Object expected.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
I am using a Websocket control under Visual Studio on a Windows Server 2012 R2, .NET 4.5
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
This is what I get back from the server after sending "hi".
The server is setup to echo back anything it receives:
B4X:
msg: Echo: {"type":"event","event":"Device_Message","params":{"message":"hello"}}
I don't know if this is a "clean JSON structure?
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
This is what I get back from the server after sending "hi".
The server is setup to echo back anything it receives:
B4X:
msg: Echo: {"type":"event","event":"Device_Message","params":{"message":"hello"}}
I don't know if this is a "clean JSON structure?

B4X:
{"type":"event","event":"Device_Message","params":{"message":"hello"}}

Is valid JSON. The msg: Echo: bit isn't as it's not encapsulated by {}.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Running the WebSocketExample, I get the following error:
When someone makes such a post we assume that you are running the example as is. If not then you need to provide all the relevant information.

WebSocketHandler module is built to work with B4J WebSocket implementation.
Remove it if you want to communicate with a different server.
 
Upvote 0
Top