so i have this app i'm trying to make that requires updating the database it's using, but it keeps giving me this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference
here is the function that updates my database:
void insertdata(String id, int num) {
// ContentValues cv = new ContentValues();
// cv.put(Enwd, Integer.toString(num));
// Log.d(LOG_TAG,String.valueOf(cv));
// if (id == null){
// Log.d("ID IS","NULL");
// } else Log.d("ID IS","NOT NULL");
String thing = "update "+TABLE_NAME+" set "+col3+ "=num"+" where _id ="+id;
Log.d("CURS ",thing);
Cursor curs = mDataBase.rawQuery(thing,null);
curs.close();
// mDataBase.update(TABLE_NAME,cv,"_id= "+id,null);
}
i've tried using ContentValue and it didn't work so i thought i'd use rawQuery, maybe i'll figure out what i'm doing wrong, plus i can't seem to be able to find tutorials the thoroughly explain how to use ContentValue, this is my first app and i'm learning how to do it while doing it, any help would be great!
EDIT: okay upon thinking i changed up insertdata:
void insertdata(String id, int num) {
SQLiteDatabase db = getReadableDatabase();
// ContentValues cv = new ContentValues();
// cv.put(Enwd, Integer.toString(num));
// Log.d(LOG_TAG,String.valueOf(cv));
// if (id == null){
// Log.d("ID IS","NULL");
// } else Log.d("ID IS","NOT NULL");
String thing = "update "+TABLE_NAME+" set "+col3+ "=num"+" where _id ="+id;
Log.d("CURS ",thing);
Cursor curs = db.rawQuery(thing,null);
curs.close();
// mDataBase.update(TABLE_NAME,cv,"_id= "+id,null);
and started getting a different error:
android.database.sqlite.SQLiteException: no such column: num (code 1): , while compiling: update wordsdata set col3=num where _id =2
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(no such column: num (code 1): , while compiling: update wordsdata set col3=num where _id =2)
EDIT2:
void insertyes(String id, int num) {
SQLiteDatabase db = getWritableDatabase();
Log.d("THE NUM",Integer.toString(num));
// ContentValues cv = new ContentValues();
// cv.put(Enwd, Integer.toString(num));
// Log.d(LOG_TAG,String.valueOf(cv));
// if (id == null){
// Log.d("ID IS","NULL");
// } else Log.d("ID IS","NOT NULL");
/* String thing = "update "+TABLE_NAME+" set "+Enyes+ "="+num +" where _id ="+id;
Log.d("CURS ",thing);
Cursor curs = db.rawQuery(thing,null);
curs.close();*/
ContentValues cv = new ContentValues();
Log.d(LOG_TAG, "--- Update table: ---");
cv.put(Enyes, num);
int updCount = db.update(TABLE_NAME, cv, "_id = "+id,null);
Log.d("THE UPDATED SHIT",Integer.toString(updCount));
}