I’m trying to check to see if a table exists in and SQLite Database with Android using this in my SQLiteOpenHelper file
// Check to see if a table exists
public boolean isTableExists(String tblName) {
String existQuery = "SELECT name FROM sqlite_master WHERE name ='" + tblName + "' and type='table'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(existQuery, null);
if(cursor != null){
cursor.close();
return true;
}
return false;
}
The call from my Activity is
if(db.isTableExists("characters") == false){
Intent p = new Intent("com.tml.rpgtodo.CREATECHARACTER");
startActivity(p);
}
I keep getting a NullPointerException on the row with the if statement. What am I doing wrong?
It sounds like
dbis null when you callif(db.isTableExists("characters") == false).I also see that you initialize db inside of “isTableExists()”. Is that a different “db”?