Android SQLite Table not created

后端 未结 5 610
名媛妹妹
名媛妹妹 2021-01-23 18:12

I\'m trying to create a table of statistics but for some reason, it doesn\'t create until I call StatisticsAdapter.insertEntry() for the first time. After that, I c

相关标签:
5条回答
  • 2021-01-23 18:32

    Create Class DatabaseHandler extends SQLiteOpenHelper

    and override like below:

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = Crate table query;
        db.execSQL(CREATE_CONTACTS_TABLE);
    }
    

    Now, you want to called SQLiteDatabase db = cintext.getWritableDatabase(); from your Activity for accessing Database table.

    0 讨论(0)
  • 2021-01-23 18:41

    This Problem has been happened when the app on device is lower version and you changing database (Add table, Create new DB, ...) and you install new version, now the app try to create new db but can't create and change modify on Database.

    the Solution is :

    JUST Change DATABASE_VERSION

    the app forced to create new DataBase

    GoodLuck

    0 讨论(0)
  • 2021-01-23 18:42

    try to extend SQLiteOpenHelper

    override

    @Override
      public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
      }
    

    The database is not actually created or opened until one of getWritableDatabase() or getReadableDatabase() is called.

    0 讨论(0)
  • 2021-01-23 18:49

    Just update the DATABASE_VERSION in your dbHelper class.

    0 讨论(0)
  • 2021-01-23 18:51

    Have you tried uninstalling the app before running the code? If the previous version of your code created db without statistics table, you have to increment your database version (DatabaseHelper.DATABASE_VERSION) to trigger onUpgrade call, which will create the table.

    The second thing you can try is to extract table name into constant and using it instead hardcoded strings. Maybe you have a typo somewhere?

    I'd also recommend pulling the database from device and checking its schema with command line sqlite client:

    adb shell
    busybox cp data/data/com.your.package/databases/database.db /sdcard
    exit
    adb pull /sdcard/database.db
    sqlite3 database.db
    .schema
    
    0 讨论(0)
提交回复
热议问题