Android SQLiteOpenHelper: Why onCreate() method is not called?

前端 未结 10 874
死守一世寂寞
死守一世寂寞 2020-12-08 18:38

I am trying to make my first Android app. I noticed that the SQLiteOpenHelper.onCreate() method is not called to create tables if the database not exists. Howev

10条回答
  •  猫巷女王i
    2020-12-08 18:50

    You can change AUTOINCREMENT to AUTO INCREMENT

    Note SQLiteOpenHelper Called onCreate when the database is created for the first time. If you create table in onCreate method you can't create new SQLiteDatabase. You can see example

        @Override
        public void onCreate(SQLiteDatabase db) {
            String stringCreateTable = "CREATE TABLE "+"tblUser"+" ( " +
                    "id TEXT PRIMARY KEY, " +
                    "name TEXT )";
            db.execSQL(stringCreateTable);
        }

提交回复
热议问题