java - threadid=1: thread exiting with uncaught exception error -
i'm recieving error of threadid=1... don't @ point in app @ sometime. not sure specific error is. i've check line 164 , don't see cause result. maybe need add manifest? here logcat.
05-08 17:19:28.796: w/dalvikvm(8683): threadid=1: thread exiting uncaught exception (group=0x40e37438) 05-08 17:19:28.806: e/androidruntime(8683): fatal exception: main 05-08 17:19:28.806: e/androidruntime(8683): java.lang.nullpointerexception 05-08 17:19:28.806: e/androidruntime(8683): @ com.example.speech.mainactivity$speechlistener.onresults(mainactivity.java:164) 05-08 17:19:28.806: e/androidruntime(8683): @ android.speech.speechrecognizer$internallistener$1.handlemessage(speechrecognizer.java:442) 05-08 17:19:28.806: e/androidruntime(8683): @ android.os.handler.dispatchmessage(handler.java:99) 05-08 17:19:28.806: e/androidruntime(8683): @ android.os.looper.loop(looper.java:137) 05-08 17:19:28.806: e/androidruntime(8683): @ android.app.activitythread.main(activitythread.java:4918) 05-08 17:19:28.806: e/androidruntime(8683): @ java.lang.reflect.method.invokenative(native method) 05-08 17:19:28.806: e/androidruntime(8683): @ java.lang.reflect.method.invoke(method.java:511) 05-08 17:19:28.806: e/androidruntime(8683): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1004) 05-08 17:19:28.806: e/androidruntime(8683): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:771) 05-08 17:19:28.806: e/androidruntime(8683): @ dalvik.system.nativestart.main(native method)
here main activity code: package com.example.speech;
import java.util.arraylist; import android.media.audiomanager; import android.media.mediaplayer; import android.os.build; import android.os.bundle; import android.os.countdowntimer; import android.app.activity; import android.content.intent; import android.speech.recognitionlistener; import android.speech.recognizerintent; import android.speech.speechrecognizer; import android.view.menu; import android.view.view.onclicklistener; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.listview; import android.util.log; public class mainactivity extends activity implements onclicklistener { private speechrecognizer mspeechrecognizer; private intent mspeechrecognizerintent; boolean reseter = false; private audiomanager maudiomanager; private volatile boolean mnospeechcountdownon; mediaplayer testsound; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); boolean available = speechrecognizer.isrecognitionavailable(this); log.d("speech", "available = " + available); testsound = mediaplayer.create(mainactivity.this, r.raw.soundclip); mspeechrecognizer = speechrecognizer.createspeechrecognizer(this); mspeechrecognizer.setrecognitionlistener(new speechlistener()); mspeechrecognizerintent = new intent(recognizerintent.action_recognize_speech); mspeechrecognizerintent.putextra(recognizerintent.extra_language_model, recognizerintent.language_model_free_form); mspeechrecognizerintent.putextra(recognizerintent.extra_calling_package, this.getpackagename()); mspeechrecognizerintent.putextra(recognizerintent.extra_speech_input_complete_silence_length_millis, 0); maudiomanager = (audiomanager) getsystemservice(this.audio_service); mspeechrecognizer.startlistening(mspeechrecognizerintent); maudiomanager.setstreammute(audiomanager.stream_system, true); log.d("speech", "mute on"); try { thread.sleep(4000); log.d("speech", "repeat"); mspeechrecognizer.startlistening(mspeechrecognizerintent); maudiomanager.setstreammute(audiomanager.stream_system, true); log.d("speech", "mute on"); } catch (interruptedexception e) { } } private countdowntimer mnospeechcountdown = new countdowntimer(5000, 5000) { @override public void ontick(long millisuntilfinished) { } @suppresswarnings("synthetic-access") @override public void onfinish() { mnospeechcountdownon = false; mspeechrecognizer.cancel(); mspeechrecognizer.startlistening(mspeechrecognizerintent); } }; @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } private class speechlistener implements recognitionlistener { @override public void onbeginningofspeech() { if (mnospeechcountdownon) { mnospeechcountdownon = false; mnospeechcountdown.cancel(); } log.d("speech", "onbeginningofspeech"); } @override public void onbufferreceived(byte[] buffer) { log.d("speech", "onbufferreceived"); } @override public void onendofspeech() { log.d("speech", "onendofspeech"); } @override public void onerror(int error) { if (mnospeechcountdownon) { mnospeechcountdownon = false; mnospeechcountdown.cancel(); } log.d("speech", "onerror"); } @override public void onevent(int eventtype, bundle params) { log.d("speech", "onevent"); } @override public void onpartialresults(bundle partialresults) { log.d("speech", "onpartialresults"); } @override public void onreadyforspeech(bundle params) { if (build.version.sdk_int >= build.version_codes.jelly_bean) { mnospeechcountdownon = true; mnospeechcountdown.start(); maudiomanager.setstreammute(audiomanager.stream_system, false); } log.d("speech", "onreadyforspeech"); try { thread.sleep(6000); log.d("speech", "repeat"); mspeechrecognizer.startlistening(mspeechrecognizerintent); maudiomanager.setstreammute(audiomanager.stream_system, true); log.d("speech", "mute on"); } catch (interruptedexception e) { }} @override public void onresults(bundle results) { log.d("speech", "results"); arraylist<string> matches = results.getstringarraylist(speechrecognizer.results_recognition); (string match : matches) { if (match.equals("one")) testsound.start(); else if (match.equals("two")) testsound.start(); } // whatever want here try { thread.sleep(1); log.d("speech", "repeat"); mspeechrecognizer.startlistening(mspeechrecognizerintent); maudiomanager.setstreammute(audiomanager.stream_system, true); log.d("speech", "mute on"); } catch (interruptedexception e) { } } @override public void onrmschanged(float rmsdb) { //log.d("speech", "onrmschanged"); } } @override public void onclick(view arg0) { //must keep onclick } }
arraylist<string> matches = results.getstringarraylist(speechrecognizer.results_recognition); if(matches!=null) { (string match : matches) /* ... */ }
matches may null if there no matches.
Comments
Post a Comment