lundi 10 août 2015

Error while inserting data into SQLiteDatabase in android

I initial object db and called its method from my current class:

        db = new DBHelper(context);
        db.addCallerInfo(FragmentCaller.iName.getText().toString(),
                FragmentCaller.sex.getSelectedItemPosition(),
                FragmentCaller.iAddress.getText().toString(),
                FragmentCaller.iTel.getText().toString(),
                FragmentCaller.callerType.getSelectedItemPosition(),
                FragmentCaller.iSpecify.getText().toString());

in DBhelper class:

public void addCallerInfo(String name,int   sex ,String address,String  tel,int  callerType_id,String  specify) {
        ContentValues values = new ContentValues();
        values.put("name", name);
        values.put("sex", sex);
        values.put("address", address);
        values.put("tel", tel);
        values.put("specify", specify);
        values.put("callerType_id", callerType_id);
        db.insert(TableHelper.TABLE_callerInfo, null, values);
    }

Then it has problem java.lang.NullPointerException: Attempt to invoke virtual method 'long android.database.sqlite.SQLiteDatabase.insert(java.lang.String, java.lang.String, android.content.ContentValues)' on a null object reference

Help please! Thanks.

Aucun commentaire:

Enregistrer un commentaire