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

前端 未结 10 834
死守一世寂寞
死守一世寂寞 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 19:00

    I have also had trouble with the SQLiteOpenHelper. What worked for me was storing a member variable

    SQLiteDatabase db;
    

    In the SQLiteOpenHelper subclass and calling

     db = getWritableDatabase();
    

    in the constructor.

    The answer to this question also includes helpful information: SQLiteOpenHelper failing to call onCreate?

    I hope this helps!

提交回复
热议问题