android TestToSpeech engine speak() method throws NoSuchMethodError -
i write app speak word typed in edittext when click button.but when click button, app crushes because of nosuchmethoderror @ speck() method of tts.the code runs without error on virtual device android version 5.1 crushes on virtual device android version 4.4.2 , xperia z 4.4.4. me plz. here activity
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); tts = new texttospeech(this, new texttospeech.oninitlistener() { @override public void oninit(int status) { if (status == texttospeech.success) { isttsready = true; int result = tts.setlanguage(locale.us); if (result == texttospeech.lang_missing_data | result == texttospeech.lang_not_supported) { toast.maketext(getapplicationcontext(), "language missing", toast.length_long).show(); } } } }); text = (edittext) findviewbyid(r.id.text); button = (button) findviewbyid(r.id.button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (isttsready) { string readit = text.gettext().tostring(); tts.speak(readit, texttospeech.queue_flush, null, null); } } }); }
and here error log
05-31 12:50:26.970: e/androidruntime(2312): fatal exception: main 05-31 12:50:26.970: e/androidruntime(2312): process: com.example.tts_test, pid: 2312 05-31 12:50:26.970: e/androidruntime(2312): java.lang.nosuchmethoderror: android.speech.tts.texttospeech.speak 05-31 12:50:26.970: e/androidruntime(2312): @ com.example.tts_test.mainactivity$2.onclick(mainactivity.java:51) 05-31 12:50:26.970: e/androidruntime(2312): @ android.view.view.performclick(view.java:4438) 05-31 12:50:26.970: e/androidruntime(2312): @ android.view.view$performclick.run(view.java:18422) 05-31 12:50:26.970: e/androidruntime(2312): @ android.os.handler.handlecallback(handler.java:733) 05-31 12:50:26.970: e/androidruntime(2312): @ android.os.handler.dispatchmessage(handler.java:95) 05-31 12:50:26.970: e/androidruntime(2312): @ android.os.looper.loop(looper.java:136) 05-31 12:50:26.970: e/androidruntime(2312): @ android.app.activitythread.main(activitythread.java:5017) 05-31 12:50:26.970: e/androidruntime(2312): @ java.lang.reflect.method.invokenative(native method) 05-31 12:50:26.970: e/androidruntime(2312): @ java.lang.reflect.method.invoke(method.java:515) 05-31 12:50:26.970: e/androidruntime(2312): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 05-31 12:50:26.970: e/androidruntime(2312): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 05-31 12:50:26.970: e/androidruntime(2312): @ dalvik.system.nativestart.main(native method)
sorry bad english. if post makes u upset, i'm sorry first question.
your code crash because use
public int speak (charsequence text, int queuemode, bundle params, string utteranceid)
that added in api level 21 can see in documentation.
for api lower 21 should use
public int speak (string text, int queuemode, hashmap<string, string> params)
change code this:
if (isttsready) { string readit = text.gettext().tostring(); if(build.version.sdk_int >= android.os.build.version_codes.lollipop) { tts.speak(readit, texttospeech.queue_flush, null, null); } else { tts.speak(readit, texttospeech.queue_flush, null); } }
Comments
Post a Comment