http://www.mrbustonian.com

无论是输入什么点击登入和注册按键都闪退

packageacitivity;importandroid.support.v7.app.AppCompatActivity;importandroid.content.ContentValues;importandroid.os.Bundle;importandroid.support.v4.app.ActivityCompat;importandroid.widget.Button;importandroid.widget.EditText;importjava.util.Date;importjava.util.regex.Matcher;importjava.util.regex.Pattern;importandroid.app.Activity;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.os.Handler;importandroid.view.KeyEvent;importandroid.view.Menu;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.TextView;importandroid.widget.Toast;importandroid.content.DialogInterface;importandroid.content.Intent;importandroid.database.Cursor;importandroid.database.SQLException;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteException;importandroid.view.Window;importandroid.support.v7.app.AlertDialog;importcom.example.a.movie.MainActivity;importcom.example.a.movie.R;importdb.DatabaseHelper;publicclassLoginActivityextendsActivity{privateTextViewtextview;//数据库名称privatestaticfinalStringDATABASE_NAME="users.db";//数据库版本号privatestaticfinalintDATABASE_VERSION=1;//表名privatestaticfinalStringTABLE_NAME="user";privateDatabaseHelperdatabaseHelper;privateSQLiteDatabasedb;privateIntentintent;privateEditTextusername;privateEditTextuserpassword;privateButtonlogin;privateButtonregister;privateLoginActivityCheckTextUtils;//初始化控件@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//databaseHelper=newDatabaseHelper(getApplicationContext());setContentView(R.layout.login);//显示自己的视图//SQLiteStudioService.instance().start(this);this.requestWindowFeature(Window.FEATURE_NO_TITLE);username=(EditText)findViewById(R.id.et_username);userpassword=(EditText)findViewById(R.id.et_userpassword);register=(Button)findViewById(R.id.bt_register);login=(Button)findViewById(R.id.bt_login);}//判断手机号码格式是否合法publicstaticbooleancheckMobile(Stringusername){Patternp=Pattern.compile("^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\d{8}$");Matcherm=p.matcher(username);returnm.matches();}publicvoidregister(Viewview){StringmPhone=username.getText().toString().trim();StringuserString=username.getText().toString();StringpwdString=userpassword.getText().toString();if(userString.equals("")||pwdString.equals("")){//弹出消息框newAlertDialog.Builder(LoginActivity.this).setTitle("错误").setMessage("帐号或密码不能为空").setPositiveButton("确定",null).show();return;}elseif(!CheckTextUtils.checkMobile(mPhone)){newAlertDialog.Builder(LoginActivity.this).setTitle("错误").setMessage("请输入有效手机号").setPositiveButton("确定",null).show();return;}else{databaseHelper=newDatabaseHelper(LoginActivity.this,DATABASE_NAME,null,DATABASE_VERSION);db=databaseHelper.getReadableDatabase();db.execSQL("insertintouser(name,password)values(?,?)",newString[]{userString,pwdString});insertData(databaseHelper.getReadableDatabase(),username,userpassword);Toast.makeText(LoginActivity.this,"注册成功!",Toast.LENGTH_LONG).show();Intentb=newIntent(LoginActivity.this,MineActivity.class);startActivity(b);}return;}privatevoidinsertData(SQLiteDatabasereadableDatabase,EditTextusername,EditTextuserpassword){ContentValuesvalues=newContentValues();values.put("name",String.valueOf(username));values.put("password",String.valueOf(userpassword));readableDatabase.insert("user",null,values);}publicvoidlogin(Viewview){Stringustring=username.getText().toString();Stringpstring=userpassword.getText().toString();if(ustring.equals("")||pstring.equals("")){//弹出消息框newAlertDialog.Builder(LoginActivity.this).setTitle("错误").setMessage("帐号或密码不能为空").setPositiveButton("确定",null).show();}else{isUserinfo(ustring,pstring);}}publicBooleanisUserinfo(Stringustring,Stringpstring){StringuserString=ustring;StringpwdString=pstring;DatabaseHelperdatabaseHelper=newDatabaseHelper(LoginActivity.this,DATABASE_NAME,null,DATABASE_VERSION);db=databaseHelper.getReadableDatabase();try{Cursorcursor=db.query(TABLE_NAME,newString[]{"user","password"},"user=?",newString[]{userString},null,null,"password");while(cursor.moveToNext()){Stringpwd=cursor.getString(cursor.getColumnIndex("password"));if(pwdString.equals(pwd)){newAlertDialog.Builder(LoginActivity.this).setTitle("正确").setMessage("成功登录").setPositiveButton("确定",newDialogInterface.OnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){//TODOAuto-generatedmethodstubIntenta=newIntent(LoginActivity.this,MineActivity.class);startActivity(a);}}).show();break;}else{Toast.makeText(LoginActivity.this,"用户名密码不正确",Toast.LENGTH_LONG).show();break;}}}catch(SQLiteExceptione){CreatTable();}returnfalse;}privatevoidCreatTable(){//TODOAuto-generatedmethodstubStringsql="CREATETABLEIFNOTEXISTS"+TABLE_NAME+"(namevarchar(15)primarykey,passwordvarchar(30));";try{db.execSQL(sql);}catch(SQLExceptionex){}}}

郑重声明:本文版权归俄罗斯254娱乐网址所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。