0
我正在开发一个应用程序,其中当一个新的活动开始时,它应该说一些字,但在讲方法总是显示我空指针异常,但在谷歌搜索,它表明我可以通过空值。我的方法如下:texttospeak接口说方法不工作
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);
}
这里是我的logcat输出:
11-21 12:14:18.985: I/System.out(307): ip : 10.184.211.143 11-21
12:14:19.035: D/AndroidRuntime(307): Shutting down VM 11-21
12:14:19.035: W/dalvikvm(307): threadid=1: thread exiting with
uncaught exception (group=0x4001d800) 11-21 12:14:19.045:
E/AndroidRuntime(307): FATAL EXCEPTION: main 11-21 12:14:19.045:
E/AndroidRuntime(307): java.lang.RuntimeException: Unable to
instantiate activity
ComponentInfo{com.example.audiobus/com.example.audiobus.AudioBusActivity}:
java.lang.NullPointerException 11-21 12:14:19.045:
E/AndroidRuntime(307): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-21 12:14:19.045: E/AndroidRuntime(307): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-21 12:14:19.045: E/AndroidRuntime(307): at
android.app.ActivityThread.access$2300(ActivityThread.java:125) 11-21
12:14:19.045: E/AndroidRuntime(307): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-21 12:14:19.045: E/AndroidRuntime(307): at
android.os.Handler.dispatchMessage(Handler.java:99) 11-21
12:14:19.045: E/AndroidRuntime(307): at
android.os.Looper.loop(Looper.java:123) 11-21 12:14:19.045:
E/AndroidRuntime(307): at
android.app.ActivityThread.main(ActivityThread.java:4627) 11-21
12:14:19.045: E/AndroidRuntime(307): at
java.lang.reflect.Method.invokeNative(Native Method) 11-21
12:14:19.045: E/AndroidRuntime(307): at
...
我在那里我打电话说出来的方法和意图的事情第一次编辑.....
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);
}
}
但我只通过ip。没有任何text.which我们必须阅读 – Ashishsingh
ip地址?,你能提供样品给我 – vinaykumar
好吧,你可以给我一些链接,我只是与你分享我的代码 – Ashishsingh