尝试使用 SQLiteOpenHelper 扩展类,但出现此错误:“android.database.sqlite.SQLitepenhelper 中没有可用的默认构造函数”以及其他“无法解析符号类别,注意,...”
class DbHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(Category.getSql());
db.execSQL(Note.getSql());
db.execSQL(Attachment.getSql());
db.execSQL(CheckItem.getSql());
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + Category.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Note.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Attachment.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + CheckItem.TABLE_NAME);
onCreate(db);
}
您需要自己定义一个显式构造函数来调用 4- 或 5-argsuper
构造函数在SQLiteOpenHelper.
例如:
public DbHelper(Context context) {
super(context, "database.db", null, 1);
}
where database.db
是您的数据库文件名,1
是版本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)