I\'m using Android\'s SQLite to create a database of levels, based on some files. I first create a SQLiteOpenHelper, and on it I call getReadableDatabase() or getWritableDatabas
Why are accessing an instance variable from an activity from inside your open helper? If I understand your code correctly, your loadLevelData()
method is a method of your open helper. Instead of what you have, why not this:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DB_TABLE_CREATE);
loadLevelData(db);
}
// Load data into the database on creation
private void loadLevelData(SQLiteDatabase db) {
...
db.insert(DB_TABLE_NAME, null, info);
}
The root of your problem is that the database
instance variable in your activity isn't assigned by the time you access it down in your DbOpenHelper... you're still in the call that's creating the database -- which happens to be dbHelper.getWritableDatabase()
-- and the result hasn't returned for the assignment.