【问题标题】:Android SDK - ActivityNotFoundExceptionAndroid SDK - ActivityNotFoundException
【发布时间】:2011-05-03 18:52:37
【问题描述】:

我正在阅读 Android Developer's Cookbook。我已经输入了他们的示例代码,它可以正确编译。但是,我在运行时遇到了这个异常。

这是书中的代码:

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);
    }
}

异常来自对startActivityForResult();的调用有谁知道可能导致这种情况的原因吗?

【问题讨论】:

  • 清单文件中是否提到了您的活动?

标签: android exception


【解决方案1】:

听起来您正在测试的设备或模拟器无法解决该意图。这是using speech recognition and determining if it is availble on a device的信息。

【讨论】:

  • 很好的电话。谢谢你。该链接非常有帮助。
  • @Theron:上面的链接抛出 404
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-28
相关资源
最近更新 更多