我已經用open()方法構建了一個數據庫輔助類,並且用onCreate()覆蓋了擴展的sqlite幫助器。 (如下所示)。儘管如此,我得到'SQLiteException,沒有這樣的表'的錯誤。我不明白,爲什麼openHelper沒有幫助?沒有這樣的表SQLite Android
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);
}
下面的代碼是爲了臨時插入一個條目,因爲數據庫不能爲其他原因爲空。這似乎完美地執行,但代碼的最後位,其中來自後就是引發錯誤
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);
那怎樣?如果你解決了它。請告訴它。並考慮接受答案 – Beasly 2011-02-14 19:02:15