You seem to have a custom insert()
method. It likely calls getWritableDatabase()
which calls getDatabase()
and it will throw this exception since onCreate()
is already called in the context of getDatabase()
. Just use db.insert()
directly where db
is the SQLiteDatabase
object passed to your onCreate()
, without calling getWritableDatabase()
. This is essentially the same issue and solution as in all the three questions you linked.
Previously your question had another, prior problem the solution to which is below, with the insert()
fix from above included:
Your table does not have the column names you specify in ContentValues
.
There's only name
and value
columns specified in the CREATE TABLE settings
but you're trying to insert data into columns Username
, Password
and personId
.
It's also useful to log full exception stack traces (and not just the message), and to read the exceptions wherever you log them.
If I understand your intent correctly, you want either three name-value pair rows like this:
ContentValues cv = new ContentValues();
cv.put("name", "Username");
cv.put("value", "");
db.insert("settings", cv);
cv.clear();
cv.put("name", "Password");
cv.put("value", "");
db.insert("settings", cv);
cv.clear();
cv.put("name", "personId");
cv.put("value", "");
db.insert("settings", cv);
or a table with single row and the given columns:
sql = "CREATE TABLE IF NOT EXISTS settings (Username text,Password text,personId)";