这是我的注册类的插入代码。我得到了:
(android.database.sqlite.SQLiteConstraintException:NOT NULL 约束失败:contacts.id(代码1299))
if (R.id.bRegister == v.getId()) {
EditText uname = (EditText) findViewById(R.id.etUsername);
EditText pass = (EditText) findViewById(R.id.etPasswprd);
EditText email = (EditText) findViewById(R.id.etEmail);
String unamestr = uname.getText().toString();
String emailstr = email.getText().toString();
String passstr = pass.getText().toString();
Contact c = new Contact();
c.setUname(unamestr);
c.setEmail(emailstr);
c.setPass(passstr);
helper.insertContact(c);
Toast temp = Toast.makeText(Register.this, "Register Done ", Toast.LENGTH_SHORT);
temp.show();
}
编辑 insertContact是:
public void insertContact(Contact c) {
db = this.getWritableDatabase();
ContentValues values = new ContentValues();
String query = " select *from contacts ";
Cursor cursor = db.rawQuery(query, null);
int count = cursor.getCount();
values.put(COLUMN_UNAME, c.getUname());
values.put(COLUMN_EMAIL, c.getEmail());
values.put(COLUMN_PASS, c.getPass());
db.insert(TABLE_NAME, null, values);
db.close();
}