Android texttospeak接口说话方法不工作

Android texttospeak接口说话方法不工作,android,nullpointerexception,Android,Nullpointerexception,我正在开发一个应用程序,当一个新的活动开始时,它应该会说一些单词,但在speak方法中总是显示空指针异常,但在Google上,它显示我们可以传递空值。我的方法如下: private void speakout(String textToSpeak) { HashMap<String, String> myHashAlarm = new HashMap(); myHashAlarm.put(TextToSpeech.Engine.KEY

我正在开发一个应用程序,当一个新的活动开始时,它应该会说一些单词,但在speak方法中总是显示空指针异常,但在Google上,它显示我们可以传递空值。我的方法如下:

private void speakout(String textToSpeak) {         
    HashMap<String, String> myHashAlarm = new HashMap();        
    myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
    String.valueOf(AudioManager.STREAM_ALARM));         
    tts.speak(textToSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
我的第一次编辑,在这里我调用了说出方法和意图的东西

protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_audio_bus);
        textView = (EditText) findViewById(R.id.ipEditText);
        welcomeNote= (TextView) findViewById(R.id.welcomeTextView);
        text = welcomeNote.getText().toString();
        text.concat(" , Please wait we are retriving information");
        System.out.println(text);
        speakout(text);
        Bundle bunble=getIntent().getExtras();
        if(bunble!=null){
               //Getting the value stored in the name "IP"
            String IP=bunble.getString("IP");
            System.out.println(IP);
                    //appending the value to the contents of textView.
             textView.append(" HI "+IP);
           }

        }
//主要活动

Bundle bundle = new Bundle();
    bundle.putString("text-to-speak","Hello world!")
    Intent intent = new Intent(<source_activity_context>,<destination_activity_class>);
    intent.putExtras(bundle);
startActivity(intent);
//全球申报

TextToSpeech tts;
//在onActivityResult中

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == Engine.CHECK_VOICE_DATA_PASS) {

            Toast.makeText(this, "we can use TTS Engine", Toast.LENGTH_LONG)
                    .show();

            tts = new TextToSpeech(this, new OnInitListener() {

                @Override
                public void onInit(int status) {

                    if (status == TextToSpeech.SUCCESS) {
                        tts.setLanguage(Locale.US);
                        tts.setSpeechRate(1.1f);
                        tts.speak(textToSpeak,
                                TextToSpeech.QUEUE_ADD, null);
                    }

                }
            });

        } else {
            Toast.makeText(this, "we can not use TTS Engine", Toast.LENGTH_LONG)
                    .show();

            Intent intent = new Intent(Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(intent);

        }

        super.onActivityResult(requestCode, resultCode, data);
    }

希望这对你有帮助。向您致意……

ip地址?,您能提供样品给我吗
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == Engine.CHECK_VOICE_DATA_PASS) {

            Toast.makeText(this, "we can use TTS Engine", Toast.LENGTH_LONG)
                    .show();

            tts = new TextToSpeech(this, new OnInitListener() {

                @Override
                public void onInit(int status) {

                    if (status == TextToSpeech.SUCCESS) {
                        tts.setLanguage(Locale.US);
                        tts.setSpeechRate(1.1f);
                        tts.speak(textToSpeak,
                                TextToSpeech.QUEUE_ADD, null);
                    }

                }
            });

        } else {
            Toast.makeText(this, "we can not use TTS Engine", Toast.LENGTH_LONG)
                    .show();

            Intent intent = new Intent(Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(intent);

        }

        super.onActivityResult(requestCode, resultCode, data);
    }