-1

i have a gridview that get data from an sqlite database and i want to delete a row by onItemLongClick but i get a error i cannot solve it

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
                               int position, long id)
{
    dataBase.delete(mDBHelper.TABLE_LIENS, mDBHelper.toString()
                                           + "="
                                           + mLienList.get(position), null);

    mLienList.remove(position);
    adapter.notifyDataSetChanged();
    Toast.makeText(Main2ActivityAdmin.this, "Lien supprimer", Toast.LENGTH_LONG).show();

    return true;
}

stack trace is:

E/AndroidRuntime: FATAL EXCEPTION: main Process: PID: 21230 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.database.sqlite.SQLiteDatabase.delete(java.lang.Stri‌​ng, java.lang.String, java.lang.String[])' on a null object reference
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

1

According to your stack trace you don't initial your SQLiteDatabase, so when use it, exception has been occurred. see this answer. it gives you an idea to modify your code.

Community
  • 1
  • 1
Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
0

if error coming from sqlite, you have to make sure that your whereClause is correct value

db.delete(table, whereClause, whereArgs);

and make sure you have initialize your database variable, in my case

db = new DB(this);
db.open();
Muklas
  • 557
  • 7
  • 11