Reputation: 13
I'm currently developing an app using the speech recognition API for a group project. I actually first implemented it about a month ago and it worked quite well since then. It's very simple, there's just an image button that starts the Voice Recognition activity when clicked. The first result is then "analysed" by the app (switch statement to check what words it contains).
The part where I'm having a problem is that when I installed the app on my phone on Thursday, it worked fine. But since yesterday it doesn't work anymore! When the button is clicked, the voice recognition interface opens, it records what I tell it, and then the screen becomes black and crashes.
Here's the logcat that I get when I run the app:
03-03 16:16:05.365: E/AndroidRuntime(12262): FATAL EXCEPTION: main
03-03 16:16:05.365: E/AndroidRuntime(12262): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { (has extras) }} to activity {com.brice/com.brice.Main}: java.lang.NullPointerException
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.ActivityThread.deliverResults(ActivityThread.java:2992)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3035)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.ActivityThread.access$1100(ActivityThread.java:127)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1189)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.os.Looper.loop(Looper.java:137)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.ActivityThread.main(ActivityThread.java:4507)
03-03 16:16:05.365: E/AndroidRuntime(12262): at java.lang.reflect.Method.invokeNative(Native Method)
03-03 16:16:05.365: E/AndroidRuntime(12262): at java.lang.reflect.Method.invoke(Method.java:511)
03-03 16:16:05.365: E/AndroidRuntime(12262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
03-03 16:16:05.365: E/AndroidRuntime(12262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
03-03 16:16:05.365: E/AndroidRuntime(12262): at dalvik.system.NativeStart.main(Native Method)
03-03 16:16:05.365: E/AndroidRuntime(12262): Caused by: java.lang.NullPointerException
03-03 16:16:05.365: E/AndroidRuntime(12262): at com.brice.Main.onActivityResult(Main.java:310)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.Activity.dispatchActivityResult(Activity.java:4649)
03-03 16:16:05.365: E/AndroidRuntime(12262): at android.app.ActivityThread.deliverResults(ActivityThread.java:2988)
03-03 16:16:05.365: E/AndroidRuntime(12262): ... 11 more
I guess the result=-1 is where the problem is but I have no idea of how to deal with that...
Here is the part of the code that deals with the speech recognition part:
/**
* Fire an intent to start the voice recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); //In order to only get the best result
startActivityForResult(intent, REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
boolean success=false; //To check if the STT worked properly
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
{
// Populate the wordsList with the String value the recognition engine thought it heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
//Outputs the message
voiceIn.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches));
success=true;
}
//Get the result as a String
first = (String) voiceIn.getItemAtPosition(0);
super.onActivityResult(requestCode, resultCode, data);
if (success){
if (first.contains("slideshow")){
loadSlideshow();
}
else{
messageTo = first; //Take the speech as the message
//Post the message to the recipient
Functions.postData(messageTo, recipient);
//Notify Granny that the message is sent
//Toast.makeText(Main.this, "Message Sent", Toast.LENGTH_LONG).show(); //Text Notifier
tts.speak("Your message has been sent", TextToSpeech.QUEUE_ADD, null); //Speech Notifier
}
}
else{ //If the Speech to Text had a problem, notify the user
tts.speak("There was a problem with the Speech Recognition Service, you should try again", TextToSpeech.QUEUE_ADD, null); //Speech Notifier
}
Once again everything worked fine for the past month and suddenly stopped yesterday (I did change the code on my machine but didn't install the new version on my phone, so the phone has the same version installed a week ago that used to work!)
Thanks a lot..
Upvotes: 0
Views: 1541
Reputation: 6263
03-03 16:16:05.365: E/AndroidRuntime(12262): Caused by: java.lang.NullPointerException
03-03 16:16:05.365: E/AndroidRuntime(12262): at
com.brice.Main.onActivityResult(Main.java:310)
The problem is on line 310 of your Main.java file, in the method onActivityResult
. If you get a chance, can you post only line 310 as a comment?
And another thing, the call to super.onActivityResult(requestCode, resultCode, data);
should be the first call in your onActivityResult
method, so move that line on up. This might not be your crash, but it might cause problems down the road.
Upvotes: 1