|
我的SQLite上有下表。
StringBuilder createSql = new StringBuilder();
createSql.append(\"create table LIBRARY ( \");
createSql.append(\"id integer primary key, \");
createSql.append(\"title text, \");
createSql.append(\"author text, \");
createSql.append(\"publisher text, \");
createSql.append(\"thumbnailUrl text, \");
createSql.append(\"formatType text, \");
createSql.append(\"contentUrl text, \");
createSql.append(\"publicationType text, \");
createSql.append(\"favorite text, \");
createSql.append(\"started text, \");
createSql.append(\"normalizedTitle text, \");
createSql.append(\"downloaded integer, \");
createSql.append(\"wasDownloaded text \");
createSql.append(\");\");
下面的代码在该表上插入一个值。
public void addLibrary(LibraryItem item) {
ContentValues row = new ContentValues();
row.put(\"title\", item.getTitle());
row.put(\"author\", item.getAuthor());
row.put(\"publisher\", item.getPublisher());
row.put(\"thumbnailUrl\", item.getThumbnail());
row.put(\"formatType\", item.getFormat());
row.put(\"contentUrl\", item.getContentUrl());
row.put(\"publicationType\", item.getPublicationType());
row.put(\"favorite\", item.isFavorite() ? \"YES\" : \"NO\");
row.put(\"id\", item.getItemId());
row.put(\"normalizedTitle\", StringUtil.normalize(item.getTitle()));
row.put(\"downloaded\", Calendar.getInstance().getTimeInMillis());
row.put(\"wasdownloaded\", item.hasContent() ? \"YES\" : \"NO\");
long id = db.insert(\"LIBRARY\", null, row);
add(id, item.getCategories());
}
但是执行它时,出现以下错误。
Error inserting id=255 formatType=null author=null title=A Cabana contentUrl=/sdcard/Digital Editions/A Cabana.pdf publicationType=Livro thumbnailUrl=https://api-dls.homolog.abrildigital.com.br/images/22/android_cover_201103092041.jpg wasdownloaded=NO downloaded=1302631109426 normalizedTitle=A Cabana favorite=NO publisher=null
android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
怎么了?