Android Question Voice Recognition and UDP


Well-Known Member
Licensed User
Longtime User
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:
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
            For i = 0 To Texts.Size -1
                Log (Texts.Get(i))
                If i < Texts.Size Then sb.Append(CM)
            Log("Invio pacchetto StringBuilder VR: " & sb.ToString)
            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
            Dim msgBack As String = BytesToString(buffer, 0, buffer.Length, "UTF8")
            Log("Successfully sent : " & remoteIP & ":" & PortOut & "  [" & msgBack & "]")
        End If
        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/
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' on a null object reference
Message: [ACK,<>,VoiceRecognition,<>,telefono casa]
** Activity (main) Resume **
WakeLock already held.
Last edited:


Well-Known Member
Licensed User
Longtime User
So has anyone ever had this problem ? You can help ?
Last edited:
Upvote 0