Question

I have a table called app_catagory. The problem is, when I try to insert a row into the table, I got this exception:

FATAL EXCEPTION : main java.lang.NullPointerException

The LogCat shows this line as the offending code:

db.insert(DATABASE_TABLE2, null, initialValues);

How can I fix it?

Code

static final String DATABASE_APP_CAT= "create table app_catagory(cat_id interprimary key autoincrement, " +
    "name text not null," +
    "date_created date , " +
    "img_name text);"; 

//Insert into catagory table 
public static void insertContact_app_cat()
{
    String[] name={"DOCTOR","PHARMACY","PATHLAB","BLOODBANK"};

    for(int i=1;i<=4;i++){
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_CAT_NAME, name[i]);
        initialValues1.put(KEY_CAT_DATE, "05-05-2014");
        initialValues2.put(KEY_CAT_IMG,"null");
        db.insert(DATABASE_TABLE2, null, initialValues);
    }
}

No correct solution

OTHER TIPS

I don't see where you are getting the db when I do an insert I call this piece of code before doing my ContentValues add stuff.

SQLiteDatabase db = this.getWritableDatabase();

Then after the insert I would close the database.

db.close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top