Android SDK - ActivityNotFoundException

馋奶兔 提交于 2019-12-13 03:35:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5874226/android-sdk-activitynotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!