2 回答
TA贡献1826条经验 获得超6个赞
您正在尝试向不存在的表添加条目,因为您没有在类的onCreate方法中创建正确的表DatabaseHelper(联系人!= 受训者)。
所以改变这个:
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "create table contacts (id integer primary key not null ," +
" username text not null, name text not null, email text not null,password text not null );";
db.execSQL(CREATE_CONTACTS_TABLE);
this.db = db;
}
到:
@Override
public void onCreate(SQLiteDatabase db) {
String createTraineeTable = "create table trainee (id integer primary key not null ," +
" username text not null, name text not null, email text not null,password text not null );";
db.execSQL(createTraineeTable);
this.db = db;
}
此外,我建议您格式化字符串并使用您定义的常量来防止这样的错误。例如:
String createTraineeTable = String.format("create table %s (%s integer primary key not null, %s text not null, %s text not null, %s text not null, %s text not null", TABLE_NAME , COL_ID, COL_USERNAME, COL_NAME, COL_PASS, COL_EMAIL);
TA贡献1829条经验 获得超9个赞
问题是创建表
@Override
public void onCreate(SQLiteDatabase db) {
String createTraineeTable = "create table trainee ("+COL_ID+" integer primary key AUTOINCREMENT ," +
COL_USERNAME+" text not null, "+COL_NAME+" text not null, "+COL_PASS+" text not null,"+COL_EMAIL+" text not null );";
db.execSQL(createTraineeTable);
this.db = db;
}
添加回答
举报