开发者

Android SDK - ActivityNotFoundException

I am working my way through the Android Developer's Cookbook. I have entered in their example code, and it compiles correctly. However, I am getting this exception at run time.

Here is the code from the book:

public class RecognizerIntentExample extends Activity {
    private static final int RECOGNIZER_EXAMPLE = 1001;
    private TextView tv;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv = (TextView) findViewById(R.id.text_result);

        //set up button listener 
        Button startButton = (Button)findViewById(R.id.trigger);
        startButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //RecoginizerIntent prompts for speech and returns text
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word or phrase\nand it will show as text");
                startActivityForResult(intent, RECOGNIZER_EXAMPLE);
            }
        });
    }

    @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        //use a switch statement for more than one request code check
        if (requestCode == RECOGNIZER_EXAMPLE && resultCode==RESULT_OK) {
            //returned data is a list of matches to the speech input
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

   开发者_开发技巧         //display on screen
            tv.setText(result.toString());
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
}

The exception is coming from the call to startActivityForResult(); Does anyone know what might be causing this?


Sounds like the device or emulator you are testing on doesn't have a way to resolve that intent. Here is information on using speech recognition and determining if it is availble on a device.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜