Java.lang.nullpointerexception Error On A Query
i'm ready to develop my second app for android, and I want to use the database. But I'm blocked by an error. This is the class: public class MyDatabase { SQLiteDatabase mDb;
Solution 1:
This is your problem:
public SQLiteDatabase getWritableDatabase() {
// TODO Auto-generated method stub returnnull;
}
You are overriding the SQLiteDatabase class getWritableDatabase
method and doing nothing in it (not opening the database or anything) and returning null, so that leads to an NPE.
Delete that method and your NPE should go away.
Solution 2:
With the code that you have shown us, the only posibility is that SQLiteDatabase mDb
is null when you call listaParametri. Are you sure that you are creating the object before calling listaParametri?
Solution 3:
//openorclose database withcreate statement
LD_ConstantData.db=openOrCreateDatabase(LD_ConstantData.dbName,SQLiteDatabase.CREATE_IF_NECESSARY,null);
LD_ConstantData.sql =new LD_MySqlOpenHelper(LD_Multi.this, LD_ConstantData.dbName, null, 1);
String sql="CREATE TABLE if not exists "+ LD_ConstantData.Table+"("+LD_ConstantData.colId+" INTEGER PRIMARY KEY AUTOINCREMENT,"+LD_ConstantData.coluserid+" TEXT NOT NULL,"+LD_ConstantData.colFirstName+" TEXT NOT NULL,"+LD_ConstantData.colLastName+" TEXT NOT NULL);";
LD_ConstantData.sql.create_table(sql);
LD_ConstantData.db.close();
//forinsert data
LD_ConstantData.sql =new LD_MySqlOpenHelper(context, database_name, null, database_version);
LD_ConstantData.db = LD_ConstantData.sql.getReadableDatabase();
LD_ConstantData.db.execSQL("INSERT INTO "+LD_ConstantData.Table +" VALUES(NULL,'"+userid+"','"+userfirstname+"','"+userlastname+"');");
LD_ConstantData.db.close();
Post a Comment for "Java.lang.nullpointerexception Error On A Query"