我正在通過Android Developer's Cookbook工作。我輸入了他們的示例代碼,並且它編譯正確。但是,我在運行時收到了這個異常。Android SDK - ActivityNotFoundException
這裏是一本書的代碼:
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();
未來有誰知道可能會導致什麼呢?
您的活動是否在清單文件中提到? – MByD 2011-05-03 18:54:09