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
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.
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
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.
Just update the DATABASE_VERSION in your dbHelper class.
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