I got android SQLiteConstraintException: error code 19: constraint failed exception. I saw there are tons of question in this topic, I've read a bunch of them, but still cant figure out what I did wrong. Mere is my table schema.
private static final String DATABASE_CREATE = "CREATE TABLE calls (call_ID
INTEGER AUTO INCREMENT PRIMARY KEY NOT NULL, caller_id TEXT NOT NULL, "+
caller_name TEXT NOT NULL, called_id TEXT NOT NULL, called_name TEXT NOT NULL," +
"start_time TEXT NOT NULL, end_time TEXT NOT NULL);";
I add one single row, and it throws the exception.
public long addCall(String caller_id, String caller_name, String called_id,
String called_name, String start, String end) {
ContentValues initialValues = createContentValues(caller_id, caller_name,called_id,called_name, start,end);
return database.insert(DATABASE_TABLE, null, initialValues);
}
I overrided the SQLHelpers onOpen method, to clear the table on every open, but it didnt help.
public void onOpen (SQLiteDatabase database){
database.execSQL("DROP TABLE IF EXISTS calls");
onCreate(database);
Log.w(DBHelper.class.getName(),"DB onOpen");
}
UPDATE: The problem is not that, I try to pass null, cause I only add these strings, and I got the error.
dbAdapter.addCall("test", "test","test", "test", "test", "test");
UPDATE 2: This is my createContentvalue method:
public static final String CALLER_ID = "caller_id";
public static final String CALLER_NAME = "caller_name";
public static final String CALLED_ID = "called_id";
public static final String CALLED_NAME = "called_name";
public static final String START = "start_time";
public static final String END = "end_time";
public static final String DATABASE_TABLE = "calls";
private ContentValues createContentValues(String caller_id, String caller_name, String called_id, String called_name, String start, String end) {
ContentValues values = new ContentValues();
values.put(CALLER_ID, caller_id);
values.put(CALLER_NAME, caller_name);
values.put(CALLED_ID, called_id);
values.put(CALLED_NAME, called_name);
values.put(START, start);
values.put(END, end);
return values;
}
createContentValuesmethod.