我创建一个像这样的表:
DB_CREATE = "create table " + DB_TABLE + " (" +
"id" + " integer, " +
"title" + " text, " + "author" + " text, " +
"image" + " text, " + "time" + " text, " +
"detail" + " text);";
_db.execSQL(DB_CREATE);
哪个_db是对SQLiteDatabase的引用。我调用方法insert()如下:
ContentValues newValues = new ContentValues();
if(object instanceof NewsBean) {
newValues.put("id", ((NewsBean) object).getId());
newValues.put("title", ((NewsBean) object).getTitle());
newValues.put("author", ((NewsBean) object).getAuthor());
newValues.put("image", ((NewsBean) object).getImage());
newValues.put("time", ((NewsBean) object).getTime());
newValues.put("detail", ((NewsBean) object).getDetail());
return db.insert(DB_TABLE, null, newValues);
}
问题在于newValues中的元素没有列为表列。怎么解决呢?我不想更改表。
最佳答案
“ id”列定义为自动递增。因此,您不得将“ id”列的值放入ContentValues。