我正在尝试制作一个简单的登录注册系统,我从 youtube 上观看了一段视频,然后出现了这个问题。
public Boolean chkmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("Select * from user where email=?", new String[]{email});
if(cursor.getCount()>0) return false;
else return true;
这是出错的地方
Cursor cursor = db.rawQuery("Select * from user where email=?", new String[]{email});
当我注册帐户时,我的应用程序崩溃了。我正在使用 sqlite。
这是数据库助手代码
public DatabaseHelper(Context context) {
super(context, "Login.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table user(email text primary key, password text)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists user");
}
public boolean insert(String email, String password) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("email", email);
contentValues.put("password", password);
long ins = db.insert("user", null, contentValues);
if(ins==-1) return false;
else return true;
