我寫好了一個(gè)MySQLiteHelper extends SQLiteOpenHelper,但是程序一直運(yùn)行錯(cuò)誤,錯(cuò)誤出在實(shí)例化數(shù)據(jù)庫(kù)那里,不知道哪里錯(cuò)了。我是這么寫的:MySQLiteHelper helper;SQLiteDatabase db=helper.getReadableDatabase();第二句過(guò)不去,這么些不行嗎?還有我看很多源碼里都有類似MySQLiteHelper helper = new MySQLiteHelper(this, DB_NAME, null, VERSION);的語(yǔ)句但我老是提示錯(cuò)誤DB_NAME和VERSION不能定義為一個(gè)變量,這是為啥?我小白,好人幫幫我吧
2 回答

暮色呼如
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
private static final String DATABASE_NAME = "test.db";
private static final int DATABASE_VERSION = 1;
public class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
這樣就可以了,參數(shù)先定義好就可以了啊。你可以再試試。

繁星淼淼
TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
"但我老是提示錯(cuò)誤DB_NAME和VERSION不能定義為一個(gè)變量",對(duì),必須定義為常量。
添加回答
舉報(bào)
0/150
提交
取消