gpt4 book ai didi

java - 编译时出现 SQLiteException : no such column itemId: ,:

转载 作者:行者123 更新时间:2023-12-02 07:29:17 25 4
gpt4 key购买 nike

public class ListsSQLiteOpenHelper extends SQLiteOpenHelper {

public static final int VERSION = 1;
public static final String DB_NAME = "lightsettings_db.sqlite";
public static final String ITEMS_TABLE = "light_setting_items";
public static final String ITEM_ID = "itemId";
public static final String ITEM_TYPE = "itemType";
public static final String ITEM_VALUE = "itemValues";
public static final String ITEM_BUSTYPE = "itemBustype";
public static final String ITEM_LIGHTTYPE = "itemLighttype";
public static final String ITEM_SELECT = "itemSelected";

public ListsSQLiteOpenHelper(Context context) {
super(context, DB_NAME, null, VERSION);
int i=0;
int y=i;
}

@Override
public void onCreate(SQLiteDatabase db) {
createTable(db);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}


protected void createTable(SQLiteDatabase db) {
db.execSQL(
"create table " + ITEMS_TABLE +" (" +
ITEM_ID + " integer primary key autoincrement not null, " +
ITEM_TYPE + " text," +
ITEM_VALUE + " text," +
ITEM_BUSTYPE + " text," +
ITEM_LIGHTTYPE + " text," +
ITEM_SELECT + " text" +
");"
);
}
}


public class EntryManagerApplication extends Application {

private ArrayList<Entry> currentEntries;

private long lineNumber = 1;

private SQLiteDatabase database;

@Override
public void onCreate() {
super.onCreate();
ListsSQLiteOpenHelper helper = new ListsSQLiteOpenHelper(this);
database = helper.getWritableDatabase();
if(currentEntries == null){
loadItems();
}
}

private void loadItems() {
currentEntries = new ArrayList<Entry>();

Cursor itemsCursor = database.query(
ITEMS_TABLE,
new String[] {ITEM_ID, ITEM_TYPE, ITEM_VALUE, ITEM_BUSTYPE, ITEM_LIGHTTYPE, ITEM_SELECT},
null, null, null, null, String.format("%s,%s", ITEM_SELECT, ITEM_TYPE));

itemsCursor.moveToFirst();
Entry e;
if(!itemsCursor.isAfterLast()){
do{
long id = itemsCursor.getLong(0);
String type = itemsCursor.getString(1);
String values = itemsCursor.getString(2);
String bustype = itemsCursor.getString(3);
String lighttype = itemsCursor.getString(4);
String boolvalue = itemsCursor.getString(5);
boolean select = Boolean.parseBoolean(boolvalue);
e = new Entry(id, type, values, bustype, lighttype);
e.setRowId(id);
e.setSelected(select);
currentEntries.add(e);
} while(itemsCursor.moveToNext());
}

itemsCursor.close();
}

public void setCurrentEntries(ArrayList<Entry> currentEntries){
this.currentEntries = currentEntries;
}

public ArrayList<Entry> getCurrentEntries(){
return currentEntries;
}

public void addEntry(Entry e){
assert(e!= null);
currentEntries.add(e);
}

public long getLineNumber() {
return lineNumber;
}

public void setLineNumber(long lineNumber) {
this.lineNumber = lineNumber;
}
}

当我尝试运行此代码时,出现错误,我不知道请帮忙。

android.database.sqlite.SQLiteException: no such column: itemId: , while compiling: SELECT itemId, itemType, itemValues, itemBustype, itemLighttype, itemSelected FROM light_setting_items ORDER BY itemSelected,itemType

最佳答案

您的CREATE TABLE命令不起作用,因为您 在结束)之前有一个逗号。

此外,SQLiteOpenHelper 不会为现有数据库调用 onCreate 方法;您必须增加 VERSION 并在 onUpdate 方法中进行必要的更改。或者,删除并重新安装您的应用。

关于java - 编译时出现 SQLiteException : no such column itemId: ,:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13135950/

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