@react-native-community/voice was working smoothly but recently it gives following error

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:347)
    at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:457)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6810)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
3

There are 3 best solutions below

0
On

In my case I got this fixed in my Speech To Text component by removing EXTRA_SPEECH_INPUT.. parameters which is passed when starting Voice Recognition.

Changing my code from this

  Voice.start('en-US', {
    EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS: 5000,
    EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS: 5000,
    EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS: 5000,
  });

to this

 Voice.start('en-US')
0
On

Well, i dont know if this will work to you, but in my case I have added this in androidManifest:

 <package android:name="com.google.android.googlequicksearchbox"/>
0
On

try to add this to AndroidManifest.xml:

<queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>