threadid = 1의 오류가 발생했습니다 ... 항상 그렇지는 않지만 언젠가는 앱의 한 지점에서 수행합니다. 내 구체적인 오류가 무엇인지 확실하지 않습니다. 164 행을 확인한 결과 아무 것도 보이지 않습니다. 어쩌면 내 매니페스트에 추가해야 할 부분이 있을까요? 여기 LogCat이 있습니다. 여기 threadid = 1 : 캐치되지 않는 예외 오류로 스레드가 종료 됨
05-08 17:19:28.796: W/dalvikvm(8683): threadid=1: thread exiting with 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): at com.example.speech.MainActivity$SpeechListener.onResults(MainActivity.java:164)
05-08 17:19:28.806: E/AndroidRuntime(8683): at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:442)
05-08 17:19:28.806: E/AndroidRuntime(8683): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 17:19:28.806: E/AndroidRuntime(8683): at android.os.Looper.loop(Looper.java:137)
05-08 17:19:28.806: E/AndroidRuntime(8683): at android.app.ActivityThread.main(ActivityThread.java:4918)
05-08 17:19:28.806: E/AndroidRuntime(8683): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 17:19:28.806: E/AndroidRuntime(8683): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 17:19:28.806: E/AndroidRuntime(8683): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
05-08 17:19:28.806: E/AndroidRuntime(8683): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
05-08 17:19:28.806: E/AndroidRuntime(8683): at dalvik.system.NativeStart.main(Native Method)
내 주요 활동 코드입니다 : 패키지 com.example.speech; 그 라인 (164)을 추측
는
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 the menu; this adds items to the action bar if it is 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);
for (String match : matches) { if (match.equals("one")) testSound.start();
else if (match.equals("two")) testSound.start();
}
// Do whatever you 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 the onClick
}
}
게시물 MainActivity 코드 – Gustek