[英]Table not creating on android device but creating on the virtual device
所以我試圖在 android 工作室中創建一個數據庫和一個表。 當我使用我的 android 手機時,數據庫已成功創建,但未創建表,但當我使用 AVD 中的虛擬設備時,數據庫和表均已創建。
public class Databases extends SQLiteOpenHelper {
public static final String dbname = "AttendanceDb11";
public Databases(@Nullable Context context) {
super(context, dbname, null, 2);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE Student12 ( _id INTEGER PRIMARY KEY AUTOINCREMENT, Name Text)";
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("Drop table if exists Student12");
onCreate(db);
}
}
這是我的代碼
看起來該應用程序在您創建表之前已經安裝。 我會執行以下操作之一:
1:卸載並重新安裝應用程序。
2:最好和更好的方法是在 onUpdate 方法中刪除並重新創建表,並在更改架構時增加數據庫版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.