gpt4 book ai didi

android - android项目中SQLite向表中插入一条记录的错误

转载 作者:行者123 更新时间:2023-11-29 18:12:49 25 4
gpt4 key购买 nike

我创建了一个这样的表:

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 中的元素没有列为表格列。如何解决?我不想换 table 。

最佳答案

“id”列被定义为自动递增。因此,您不得将“id”列的值放入 ContentValues。

关于android - android项目中SQLite向表中插入一条记录的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9771943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com