gpt4 book ai didi

android - 表 "Tablename"没有名为 "columnname"的列,但它有一个

转载 作者:行者123 更新时间:2023-11-30 22:42:16 28 4
gpt4 key购买 nike

我用这个创建了一个表,而“KEY_IMAGE_PATH”是“图像”

private class foodieItemDBOpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_CREATE = "create table "
+ DATABASE_TABLE + "(" + KEY_ID
+ " integer primary key autoincrement, " +KEY_IMAGE_PATH +" text no null, "
+ KEY_RATING + " text, " + KEY_TITLE + " text);";

public foodieItemDBOpenHelper(Context c, String dbname,
SQLiteDatabase.CursorFactory factory, int version) {
super(c, dbname, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}

在尝试将数据添加到数据库时抛出此错误:

 E/SQLiteLog﹕ (1) table foodieItems has no column named image
06-12 13:40:34.469 12377-12377/mi.ur.de.foodieappstarterproject E/SQLiteDatabase﹕ Error inserting rating=3 title=null image=/storage/sdcard/Pictures/FoodieApp/IMG_20150612_134034.jpg
android.database.sqlite.SQLiteException: table foodieItems has no column named image (code 1): , while compiling: INSERT INTO foodieItems(rating,title,image) VALUES (?,?,?)

我的数据库设置有问题吗?

编辑:插入查询

public long addFoodieItem(FoodieItem item) {
ContentValues newFoodieValues = new ContentValues();


newFoodieValues.put(KEY_IMAGE_PATH, item.getImagePath());
newFoodieValues.put(KEY_RATING, 3);
newFoodieValues.put(KEY_TITLE, item.getTitle());

return db.insert(DATABASE_TABLE,null, newFoodieValues);
}

最佳答案

我建议您将查询更改为:

private static final String DATABASE_CREATE = "CREATE TABLE "
+ DATABASE_TABLE + "(" + KEY_ID
+ " INTEGER primary key autoincrement, " +KEY_IMAGE_PATH +" TEXT NOT null, "
+ KEY_RATING + " TEXT, " + KEY_TITLE + " TEXT);";

必须为 TEXT NOT null ,这就是无法创建 KEY_IMAGE_PATH 中定义的字段的原因!

此更改后,您可能需要卸载您的应用程序,因为表的结构已更改!

关于android - 表 "Tablename"没有名为 "columnname"的列,但它有一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30804726/

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