初步学习Android,创建电话拨号器项目,项目编写完之后,在真机或者模拟器上运行都会报:异常停止运行;
警告:05-13 07:57:00.662: W/dalvikvm(339): threadid=1: thread exiting with uncaught exception (group=0x40015560)
public class CallActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
Button button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new ButtonClickListener());
}
public final class ButtonClickListener implements View.OnClickListener {
public void onClick(View v) {
// TODO Auto-generated method stub
EditText mobileText = (EditText) findViewById(R.id.mobile);
String number = mobileText.getText().toString();
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
**intent.setData(Uri.parse("tel" + number));**
startActivity(intent);
}
}
}
错误:05-13 07:57:00.682: E/AndroidRuntime(339): FATAL EXCEPTION: main
05-13 07:57:00.682: E/AndroidRuntime(339): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel5554 }
05-13 07:57:00.682: E/AndroidRuntime(339): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
05-13 07:57:00.682: E/AndroidRuntime(339): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
05-13 07:57:00.682: E/AndroidRuntime(339): at android.app.Activity.startActivityForResult(Activity.java:2827)
初步判断是Activity没有找到问题,不是java代码问题,如果是java代码问题修改后的java代码就会报错的:
后来发现问题条用intent.setData(Url.parse(“tel”+number));这个语法错误;intent.setData(Url.parse(“tel”+number));