Note that there are some explanatory texts on larger screens.

plurals
  1. POstart activity for result gets null pointer exception
    primarykey
    data
    text
    <p>I put speech function into a new class called voiceAssistants, however, when i start it, it always give me an null pointer exception error.</p> <p>voice Assistants:</p> <pre><code>public class VoiceAssistants { private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234; private static VoiceActivityHelper voiceAssistants; public VoiceAssistants(){ voiceAssistants = new VoiceActivityHelper(); } /** * Start voice input */ public void starVoiceAssistants(){ this.voiceAssistants.startVoiceRecognitionActivity(); } private static class VoiceActivityHelper extends Activity { private static ArrayList&lt;String&gt; matches; public ArrayList&lt;String&gt; getResultSet(){ return matches; } private void startVoiceRecognitionActivity() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, String.format( "%s_%s", Locale.getDefault().getLanguage(), Locale .getDefault().getCountry())); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); //error happen here!!! startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); } } } </code></pre> <p>But when I put it into normal activity that generated by new project, it won't tall any error. log infos:</p> <pre><code>E/AndroidRuntime(22769): java.lang.NullPointerException E/AndroidRuntime(22769): at android.app.Activity.startActivityForResult(Activity.java:2827) E/AndroidRuntime(22769): at panda.com.db.VoiceAssistants$VoiceActivityHelper.startVoiceRecognitionActivity(VoiceAssistants.java:56) E/AndroidRuntime(22769): at panda.com.db.VoiceAssistants$VoiceActivityHelper.access$1(VoiceAssistants.java:47) E/AndroidRuntime(22769): at panda.com.db.VoiceAssistants.starVoiceAssistants(VoiceAssistants.java:24) </code></pre> <p>plz help, thank you!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload