An exception happened in my app when I add a new item into my database.
Error inserting time=2016年05月14日 23:42:03 content=zxdc
android.database.sqlite.SQ
You have the following NOT NULL values in your database definition:
CONTENT
PATH
VIDEO
TIME
But in your addDB you only put CONTENT and TIME in ContentValues so it definitely looking for PATH and VIDEO too. If they aren't present, it will give the error. There are two solution:
Solution 1:
remove NOT NULL constraint from VIDEO and PATH:
db.execSQL("CREATE TABLE " + TABLE_NAME + "(" + ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT," + CONTENT
+ " TEXT NOT NULL," + PATH
+ " TEXT," + VIDEO
+ " TEXT," + TIME
+ " TEXT NOT NULL)");
Solution 2:
add VIDEO and PATH to ContentValues:
private void addDB() {
ContentValues cv = new ContentValues();
cv.put(SecretAlbumDB.CONTENT, editText.getText().toString());
cv.put(SecretAlbumDB.TIME, getTime());
cv.put(SecretAlbumDB.VIDEO, getVideo());
cv.put(SecretAlbumDB.Path, getPath());
dbWriter.insert(SecretAlbumDB.TABLE_NAME, null, cv);
}
For sure you have declared your all fields (columns) as NOT NULL
and you've not put the value to those fields while inserting cv
. Either make those columns null
acceptable or put all the values to cv
for every Columns that are NOT NULL
.