voice icon indicating copy to clipboard operation
voice copied to clipboard

java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Iterator java.util.ArrayList.iterator()' on a null object reference [ANDROID]

Open mehdinourollah opened this issue 2 years ago • 9 comments

When I use it on Android the app crashes and I've got this error from logcat

    Process: com.******, PID: 18659
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Iterator java.util.ArrayList.iterator()' on a null object reference
        at com.wenkesj.voice.VoiceModule.onResults(VoiceModule.java:348)
        at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:459)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7664)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)```

mehdinourollah avatar Apr 29 '22 14:04 mehdinourollah

It's happening the moment that the speech is finished ! So it shows the results but when it tries to end the speech it crashes with above logs

mehdinourollah avatar Apr 29 '22 14:04 mehdinourollah

The VoiceModule.java the mentioned part is this part :

  public void onResults(Bundle results) {
    WritableArray arr = Arguments.createArray();

    ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    for (String result : matches) {
      arr.pushString(result);
    }
    ...

mehdinourollah avatar Apr 29 '22 14:04 mehdinourollah

In my case, this solution works : [@react-native-community/voice or react-native-voice / voice gives exception java.lang.NullPointerException at com.wenkesj.voice.VoiceModule.onResults](https://stackoverflow.com/questions/72213425/react-native-community-voice-or-react-native-voice-voice-gives-exception-java/72213426#72213426)

Thanhal-P-A avatar May 12 '22 09:05 Thanhal-P-A

As far as I checked it's not a solution ...It just removed some parameters from Start function ( which I can't )

In my case, this solution works : [@react-native-community/voice or react-native-voice / voice gives exception java.lang.NullPointerException at com.wenkesj.voice.VoiceModule.onResults](https://stackoverflow.com/questions/72213425/react-native-community-voice-or-react-native-voice-voice-gives-exception-java/72213426#72213426)

mehdinourollah avatar Jun 01 '22 13:06 mehdinourollah

@mehdinourollah did you find any solution for this without removing the parameters?

Nikit-Singh avatar Jul 03 '22 18:07 Nikit-Singh

No I couldn't Unfortunately

mehdinourollah avatar Jul 03 '22 19:07 mehdinourollah

I managed to fix the crash on android by removing EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS from the options in Voice.start

Alaaeddine-chakroun avatar Dec 23 '22 15:12 Alaaeddine-chakroun

I made simple fix and pull request. #435 I need your usage tests and feedback.

goheroes avatar May 09 '23 06:05 goheroes