今天写了Android的数据库的登陆验证的代码,运行后点击登陆没反应,控制台没有错误,日志又错误看不懂,看来自己还是只学了一个皮毛,烦,源码附上
public class MainActivity extends Activity {
private MyDBHelper dbHelper;
private EditText username;
private EditText userpassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
dbHelper = new MyDBHelper(this,"FeiHuaLin.db",null,1);
}
//点击注册按钮进入注册页面
public void logonClicked(View view){
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
//点击登录按钮
public void loginClicked(View view) {
username=(EditText)findViewById(R.id.account);
userpassword=(EditText)findViewById(R.id.password);
String userName=username.getText().toString();
String passWord=userpassword.getText().toString();
if (login(userName,passWord)) {
Toast.makeText(MainActivity.this, "登陆成功(ZY,111)", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this, "登陆失败", Toast.LENGTH_SHORT).show();
}
}
//验证登录
public boolean login(String username,String password) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
String sql = "select * from User where name=? and password=?";
Cursor cursor = db.rawQuery(sql, new String[] {username, password});
if (cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}
}
android:layout_height="match_parent"
android:stretchColumns="1" >
android:text="Account:" />
android:layout_height="wrap_content"
android:hint="Input your account" />
android:text="Password:" />
android:layout_height="wrap_content"
android:inputType="textPassword" />
android:layout_height="wrap_content" />
android:text="Remember password" />
05-05 15:06:14.208: E/mqq(3268): waitInit when empty:
05-05 15:06:14.208: E/mqq(3268): java.lang.RuntimeException:
05-05 15:06:14.208: E/mqq(3268): at mqq.app.MobileQQ.waitAppRuntime(MobileQQ.java:810)
05-05 15:06:14.208: E/mqq(3268): at com.tencent.common.app.BaseApplicationImpl.getRuntime(ProGuard:198)
05-05 15:06:14.208: E/mqq(3268): at com.tencent.mobileqq.app.DeviceProfileManager.a(ProGuard:284)
05-05 15:06:14.208: E/mqq(3268): at com.tencent.mobileqq.statistics.battery.BatteryStatsImpl.a(ProGuard:223)
05-05 15:06:14.208: E/mqq(3268): at com.tencent.mobileqq.statistics.battery.BatteryStatsImpl.a(ProGuard:154)
05-05 15:06:14.208: E/mqq(3268): at amky.run(ProGuard:85)
05-05 15:06:14.208: E/mqq(3268): at mqq.os.MqqHandler.handleCallback(MqqHandler.java:337)
05-05 15:06:14.208: E/mqq(3268): at mqq.os.MqqHandler.dispatchMessage(MqqHandler.java:97)
05-05 15:06:14.208: E/mqq(3268): at mqq.os.MqqHandler$NativeHandler.dispatchMessage(MqqHandler.java:350)
05-05 15:06:14.208: E/mqq(3268): at android.os.Looper.loop(Looper.java:135)
05-05 15:06:14.208: E/mqq(3268): at android.os.HandlerThread.run(HandlerThread.java:61)