jeudi 26 février 2015

How do you reference the same instance of a class when its passed in as a parameter in another class?



I have extended SQLiteOpenHelper in this one class and have used the following method to update my database.



public void UpDateDataBase(ItemClass itemClass){

SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_ItemClass_NAME, itemClass.getTaskName());
contentValues.put(KEY_STATUS, itemClass.getStatus());
db.update(TABLE_NAME, contentValues, KEY_ID + " = ?", new String[]{String.valueOf(itemClass.getId())});
}

public static DataBaseHelper getInstance(){
return dbHelper;
}


}


And when I try to call the UpdateDataBase() method in my other class using



DataBaseHelper.getInstance().UpDateDataBase(new ItemClass());


It tells me that I'm referencing a null object. How do I reference the same instance of the class?


Thank you.


Attempt to invoke virtual method 'void demoapp.app.android.sqlitedatabaseapplication.DataBaseHelper.UpDateDataBase(demoapp.app.android.sqlitedatabaseapplication.ItemClass)' on a null object reference




Aucun commentaire:

Enregistrer un commentaire