java.lang.NullPointerException
at anywheresoftware.b4j.object.WebSocketModule$Adapter.onWebSocketText(WebSocketModule.java:121)
when my b4a client app starts the first time.
I close the app and restart it and i do not get that error message, all works well.
Note that the connection is successful in both cases, but on app first start the subsequent requests to the server do not work and do not return errors on the server.
After the first client compile and run (and therefore its connection), there will be that error message on the server. Running again the client app, the message will not be there and both sides will receive a text message.
[Molto interessante la tua PrivacyCard. Ho letto che vorresti che il tutto rimanesse in Italia, ma ugualmente ti consiglierei di mettere anche la versione inglese dei testi del sito.
Very interesting your PrivacyCard. I have read that you would like that the whole thing remained in Italy, but I recommend you to also put the English version of the site]
Are you sending any message from the client immediately after the connection? If yes then try to use CallSubDelayed in the client code to send the message only after the connection event.
Mmmmm... I checked your code.
When you start the service SrvCommun you chect the wsh websocket. If it is not initialized od not connected you call a Sub Connect.
B4X:
Private Sub Connect
modUtils.LogSub("srvCommun", "Connect")
wsh.Initialize(Me, "wsh")
wsh.ws.Connect(Main.ServerLink)
End Sub
This sub performs wsh.ws.initialize (and set the callback) and then open the connection. But I think you shoud re-check the wsh.isInitialized status before the connect...
Are you sending any message from the client immediately after the connection? If yes then try to use CallSubDelayed in the client code to send the message only after the connection event.
Public Sub wsh_Connected
modUtils.LogSub("srvComm", "wsh_Connected")
Private mapData As Map : mapData.Initialize
mapData.Put("msg", "Hi, I'm connected")
wsh.SendEventToServer("RaisedByClient_Msg", mapData)
End Sub
This is the first msg sent from client to server (and you know how SendEventToServer works)
Mmmmm... I checked your code.
When you start the service SrvCommun you chect the wsh websocket. If it is not initialized od not connected you call a Sub Connect.
B4X:
Private Sub Connect
modUtils.LogSub("srvCommun", "Connect")
wsh.Initialize(Me, "wsh")
wsh.ws.Connect(Main.ServerLink)
End Sub
This sub performs wsh.ws.initialize (and set the callback) and then open the connection. But I think you shoud re-check the wsh.isInitialized status before the connect...
No, I didn't try. I don't use b4j (give me the compiled JAR file and I'll try)
"At first run wsh is surely not initialized" is exacly what I mean.
Actually you check if .Isinizialized and if not you Initialize the wsh.
But IMMEDIATELY after this call you try to open the connection...
My iphotesis: Initalize is performed by the WebSocket library, in another thred and therefore it could be asynchronous.
You are trying to connect wsh.ws.Connect(Main.ServerLink) an object that is still not initialized. The pointer to this object is currently NULL and it throws the exception.
Try to insert some delay between Initialize and connect, something like "Loop until wsh.IsInizialized"
No, I didn't try. I don't use b4j (give me the compiled JAR file and I'll try)
"At first run wsh is surely not initialized" is exacly what I mean.
Actually you check if .Isinizialized and if not you Initialize the wsh.
But IMMEDIATELY after this call you try to open the connection...
My iphotesis: Initalize is performed by the WebSocket library, in another thred and therefore it could be asynchronous.
You are trying to connect wsh.ws.Connect(Main.ServerLink) an object that is still not initialized. The pointer to this object is currently NULL and it throws the exception.
Try to insert some delay between Initialize and connect, something like "Loop until wsh.IsInizialized"
I found Commandant & Commander are synonyms and Commandant is most used. Anyway, ok, i call you Captain (degraded, lol).
However, I have "found" the error due to the fact that I searched for the server jar... I have not found it, then I realized that I was using the debug mode. So, you helped me anyway.