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
I had a similar problem however it was not the OnCreate
call that was the issue.
In the example code above, Kevin explained that the OnCreate
is not called if the database already exists. However if, like me, you are using multiple tables from separate activities, then though you may have created the database already, the table associated with this activity may yet have not been created. Hence when you attempt to set the cursor data on a non-existent table, you will invoke an exception.
My solution was define a separate class called CreateTable
which is called both from the OnCreate
override and from the constructor after the
db = getWritableDatabase();