當我使用的Android錯誤:SQLite數據庫的OnCreate
SQLite數據庫下面的代碼:
public class DBHelper extends SQLiteOpenHelper{
public String test="";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
test="here11";
// Category table create query
String CREATE_CATEGORIES_TABLE = "CREATE TABLE " + TABLE_LABELS + " ("+ KEY_Phone + " TEXT PRIMARY KEY, " + KEY_NAME + " TEXT, " + KEY_email + " TEXT, " + KEY_Pass + " TEXT, " + KEY_MomNum + " TEXT)";
db.execSQL(CREATE_CATEGORIES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS);
// Create tables again
onCreate(db);
}
}
我把一測試字符串是否進入到的onCreate功能
並在主類:
DBHelper db = new DBHelper(getApplicationContext());
Toast.makeText(getApplicationContext(), db.test, Toast.LENGTH_LONG).show();
但我顯示空的土司爲什麼?
謝謝。
您是否清除應用程序的緩存/數據?否則它不會再次創建數據庫,這可能是爲什麼 – Stupidus
將getApplicationContext更改爲此 –