我已经建立了一个数据库帮助类,其中包含一个open()方法,并使用覆盖onCreate()的方式扩展sqlite帮助类(如下所示)。尽管如此,我仍然遇到了“SQLiteException,没有这样的表”错误。我不明白,为什么OpenHelper没有帮助到我?
public void open() {
try{
db = openHelper.getWritableDatabase();
} catch (SQLiteException e) {
db = openHelper.getReadableDatabase();
}
}
//other stuff
public static final String database_create = "create table " + database_table + " (" + primary_key + " integer primary key autoincrement, "
+ company_column + " text not null, " + product_column + " text not null);";
@Override
public void onCreate(SQLiteDatabase _db) {
_db.execSQL(database_create);
}
以下代码旨在临时插入一个条目,因为数据库由于其他原因不能是空的。它似乎执行得很完美,然而最后一行代码(即“after”之后的代码)却导致了错误。
CompanyAndProductDatabaseAdapter cpdAdapter = new CompanyAndProductDatabaseAdapter(this);
cpdAdapter.open();
errorguard = cpdAdapter.insertPair("Loading", "...");
cpdAdapter.close();
//other stuff
cpdAdapter.open();
Cursor cursor = cpdAdapter.getAllPairsCursor(); //error here
cursor.requery();
startManagingCursor(cursor);