Android Sqlite Exception. Unable To Instantiate Activity
Solution 1:
The Activity
is created only after onCreate
calling. So when you are calling
private final DbOpenHelper dbOpen = new DbOpenHelper(MainMonitor.this);
activity still not created.
Remove final
modifier from your db option and init it in separate method after onCreate
calling.
You should do smth like this:
publicclassMainMonitorextendsActivity {
private DbOpenHelper dbOpen;
private SQLiteDatabase db;
private ContentValues cv;
@OverrideprotectedvoidonResume() {
super.onResume();
initDb();
}
privatevoidinitDb() {
dbOpen = newDbOpenHelper(MainMonitor.this);
db = dbOpen.getWritableDatabase();
cv = newContentValues();
}
//....your code
}
Solution 2:
You are getting a null pointer exception probably in the onCreate - i dont understand the INSERT INTO network(activity) - surely its just INSERT INTO network - you do insert into table name
But that is not how you are meant to do an insert either - use this example
db = this.getWriteableDatabase();
ContentValuesinsertValues=newContentValues();
insertValues.put("Description", "Electricity");
insertValues.put("Amount", 500);
insertValues.put("Trans", 1);
insertValues.put("EntryDate", "04/06/2011");
db.insert("CashData", null, insertValues);
Solution 3:
First you can check without inserting. If database is created then you can test to insert. check data folder, database is created or not.
Solution 4:
I believe this is the line giving you trouble:
sqliteDb.execSQL("INSERT INTO network(activity) VALUES(1)");
Try,
ContentValuesv=newContentValues();
v.put(ACTIVITY, 1);
sqliteDb.insert(TABLE_NAME, null, v);
Make sure you don't insert an empty ContentValues
object or else an exception will be thrown.
Solution 5:
your error lies in this line
sqliteDb.execSQL("INSERT INTO network(activity) VALUES(1)");
since you are trying to refer to the activity
column in your table, you should surround it with quotes. It should be like this
sqliteDb.execSQL("INSERT INTO network(\"activity\") VALUES(1)");
or
sqliteDb.execSQL("INSERT INTO network(" + ACTIVITY + ") VALUES(1)");
Post a Comment for "Android Sqlite Exception. Unable To Instantiate Activity"