开始学Android,在写一个软件的注册页面时出现了问题。点击绑定好的页面跳转的按钮,却显示该工程stop,跳转失败。但是!我已经在AndroidMainfest中定义好了activity,实在找不出错误。求助各位。
以下是代码部分。由于发送验证码部分不是我负责的,所以直接在数据类中把验证码定为1111
public class register_1_phone extends Activity{
private Button sure_code;
private EditText edit_phone;
private EditText edit_code;
private Button get_code;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.register_1_phone);
findView();
sure_code.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String mCode=edit_code.getText().toString().trim();
//获得线程发出的验证码准备与用户输入的验证码比较
boolean judge=isSameCode(mCode);
if(judge==true)
{
Intent intent=new Intent(register_1_phone.this,register_2_user.class);
startActivity(intent);
}
else
//弹出对话框显示错误
{
creatdialog();
}
}
private boolean isSameCode(String mCode) {
String code=data_share.get_code();
if(code.equals(mCode))
return true;
else
return false;
}
private void creatdialog() {
AlertDialog.Builder b=new Builder(register_1_phone.this);
b.setMessage("您输入的验证码有误,check一下吧~");
b.setTitle("验证码错误");
b.setNegativeButton("重试", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
dialog.dismiss();
}
});
b.create().show();
}
});
get_code.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String mphone=edit_phone.getText().toString().trim();//获取手机号
boolean judge=isMobile(mphone);
if(judge==false)
{
//如果手机号不合法,提示重输
creatdialog();
}
else{
data_share.set_phone(mphone);
//接下来新建一个线程去请求验证码
}
}
//判断手机号是否合法的函数
private boolean isMobile(String mphone) {
String num="[1][358]\\d{9}";//【1】表示第一位数字为1,【358】表示第二位必为3/5/8中的一个,\\d{9}表示后面是可以是0~9的数字,有9位
if(TextUtils.isEmpty(mphone)){
return false;
}
else{
return mphone.matches(num);//字符串是否在给定的正则表达式匹配
}
}
//创建显示手机号错误的对话框
private void creatdialog() {
AlertDialog.Builder b=new Builder(register_1_phone.this);
b.setMessage("您输入了一个来自火星的手机号,换个地球手机号吧~");
b.setTitle("手机号错误");
b.setNegativeButton("重试", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
dialog.dismiss();
}
});
b.create().show();
}
});
}
//绑定界面的控件
private void findView() {
sure_code=(Button)findViewById(R.id.sure_vrification_code);
edit_phone=(EditText)findViewById(R.id.edit_phone);
edit_code=(EditText)findViewById(R.id.edit_vrification_code);
get_code=(Button)findViewById(R.id.get_vrification_code);
}
}