I know this was asked and answered quite some time ago, but i'm still having problems with my code and I am very new to Android dev.
I would like to check that a table exists before moving forward with any processing.
I found : https://stackoverflow.com/a/7863401/3669516
But I still get an error:
E/SQLiteLog: (1) no such table: challenge
W/Challenge_DBAdapter: no such table: challenge (code 1): , while compiling: SELECT COUNT(*) FROM challenge
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database. (no such table: challenge (code 1): , while compiling: SELECT COUNT(*) FROM challenge)
Here is my Try()Catch{} snippet
try{
Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM challenge",null);
Log.w(TAG, "check cursor");
if(cursor != null)
if(cursor.getCount() < 1) {
if(setupDB())
db_is_set = true;
} else {
db_is_set = true;
}
} catch (Exception e){
Log.w(TAG, e.getMessage());
}
My code crashes before hitting the Log for 'check cursor'.
My desired result is to get a boolean (of sorts) so i can continue processing. Currently, I have the code working by calling the desired function "setupDB()" in the catch block, but I would like to know why my program fails when it hits the query vs going into the if(cursor != null) block.