Hi all,
in my project I have a working UDP socket that do some things.
Now I want use Voice Recognition, then send the result string over UDP socket, but for some strange reasons the
already initialized UDP socket is Null in the Voice Recognition _Result event.
The application will not crash here, the word is returned as expected, but in the log I see a 'red' error that packet cannot be sent because socket is Null.
When _Result is called, the app is paused, is this the problem ?
How I can solve it ?
Many thanks.
Here is my _Ready event sub:
and this is the log:
in my project I have a working UDP socket that do some things.
Now I want use Voice Recognition, then send the result string over UDP socket, but for some strange reasons the
already initialized UDP socket is Null in the Voice Recognition _Result event.
The application will not crash here, the word is returned as expected, but in the log I see a 'red' error that packet cannot be sent because socket is Null.
When _Result is called, the app is paused, is this the problem ?
How I can solve it ?
Many thanks.
Here is my _Ready event sub:
B4X:
Sub VR_Result (success As Boolean, Texts As List)
Log("VR Success: " & success)
If success = True Then
If Texts.Size > 1 Then
Dim sb As StringBuilder
sb.Initialize
sb.Append("ACK").Append(CM).Append("VoiceRecognition").Append(CM)
For i = 0 To Texts.Size -1
Log (Texts.Get(i))
sb.Append(Texts.Get(i))
If i < Texts.Size Then sb.Append(CM)
Next
Log("Invio pacchetto StringBuilder VR: " & sb.ToString)
SendPacket(sb.ToString)
Else
Log("Invio pacchetto VR: " & "ACK" & CM & "VoiceRecognition" & CM & Texts.Get(0))
'SendPacket("ACK" & CM & "VoiceRecognition" & CM & Texts.Get(0))
Log (Texts.Get(0))
Dim data As String = "ACK" & CM & "VoiceRecognition" & CM & Texts.Get(0)
Dim pkt As UDPPacket
Dim buffer() As Byte = data.GetBytes("UTF8")
pkt.Initialize(buffer, remoteIP, PortOut) 'DATA,HOST,PortOut ' Inizializza il pacchetto in invio
udp.Send(pkt)
Dim msgBack As String = BytesToString(buffer, 0, buffer.Length, "UTF8")
Log("Successfully sent : " & remoteIP & ":" & PortOut & " [" & msgBack & "]")
End If
Else
Log("Cannot recognize voice")
ToastMessageShow("Cannot recognize voice", True)
End If
End Sub
and this is the log:
Logger connesso a: asus ASUS_Z00LD
--------- beginning of main
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create (first time) **
File.ExternalWritable = true
Main Dir = /data/user/0/com.vdisplay.pro/files
Activity.NumberOfViews on start: 4
** Activity (main) Resume **
VR: Ciao, parla con me ...
** Activity (main) Pause, UserClosed = false **
running waiting messages (1)
VR Success: true
Invio pacchetto VR: ACK,<>,VoiceRecognition,<>,telefono casa
telefono casa
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.net.DatagramSocket.send(java.net.DatagramPacket)' on a null object reference
Message: 192.168.178.36:8889 [ACK,<>,VoiceRecognition,<>,telefono casa]
** Activity (main) Resume **
WakeLock already held.
Last edited: