I am trying to add multiple records in SQLite with for loop likewise, but data is not fetched while calling from function and getting null pointer exception:
ContentValues[] ans7 = new ContentValues[4];
for(int j =0; j<4; j++){
ans7[j] = new ContentValues();
ans7[j].put(KEY_ANSWER, Utils.DB_NULL_INT_VALUE);
ans7[j].put(KEY_TYPE, Utils.TYPE_NORMAL);
ans7[j].put(KEY_RESOURCE, ans7Array[j]);
if(j==1) {
ans7[j].put(KEY_IS_CORRECT, Utils.CORRECT);
}else{
ans7[j].put(KEY_IS_CORRECT, Utils.INCORRECT);
}
ans7[j].put(KEY_QUESTION_ID, 7);
long i = db.insert(TABLE_ANSWER, null, ans7[j]);
Log.e("Answer type 3", "que 7 " + i);
}
I don't know whether it is if-else clause which causing it.