gpt4 book ai didi

android - 非法状态异常 : get field slot from row 0 col 3

转载 作者:行者123 更新时间:2023-11-30 04:31:42 26 4
gpt4 key购买 nike

我的应用程序总是在开始时崩溃,错误在日志中

我的代码:

    private void onCreateDBAndDBTabled() {
myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
//myDB.execSQL("DROP TABLE " + MY_DB_TABLE);
myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
+ " (_id integer primary key autoincrement, name varchar(100), rate integer(1), eattime varchar(100),image BLOB)"
+";");
ArrayList<Pizza> list = new ArrayList<Pizza>();
Cursor cursor = this.myDB.query(MY_DB_TABLE, new String[] { "name", "rate","eattime" },null,null,null,null,null,null);
if (cursor.moveToFirst()) {
do {
Log.e("XXX", "Courser Enter: " + cursor.getString(0));
Pizza pizza = new Pizza();
pizza.title= cursor.getString(0);
pizza.rate = cursor.getInt(1);
pizza.date = cursor.getString(2);

ByteArrayInputStream inputStream = new ByteArrayInputStream(cursor.getBlob(3));
pizza.picture = BitmapFactory.decodeStream(inputStream);
list.add(pizza);
}
while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
Log.e("XXX", "Count:" + list.size());
//Log.e("XXX", "Item[0] -->" + list.toArray()[0].toString());
CustomAdapter aa = new CustomAdapter(this, R.layout.customlistitem,list);
Log.e("XXX", String.valueOf(aa.getCount()));
lv.setAdapter(aa);
aa.notifyDataSetChanged();
}

添加披萨:

private void addData() {
myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
//myDB.execSQL("DROP TABLE " + MY_DB_TABLE);
myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
+ " (_id integer primary key autoincrement, name varchar(100), rate integer(1), eattime varchar(100),image BLOB)"
+";");
if(!name.getText().equals("") && rating.getRating()!=0.0)
{
Log.e("XXX", "Enter_Insert");
Calendar cal = Calendar.getInstance();
DateFormat formatter = new SimpleDateFormat();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Bitmap bt = ((BitmapDrawable)iv.getDrawable()).getBitmap();
bt.compress(Bitmap.CompressFormat.PNG, 100, out);
ContentValues cv = new ContentValues();
cv.put("image", out.toByteArray());
cv.put("name", name.getText().toString());
cv.put("eattime", formatter.format(cal.getTime()));
cv.put("rate", rating.getRating());
myDB.insert(MY_DB_TABLE, null, cv);

//myDB.execSQL("INSERT INTO "+ MY_DB_TABLE + "(name,rate,eattime,image) VALUES +" + + ", " ++ " , datetime('now', 'localtime'), " );
}

}

日志:

09-30 12:16:26.755: ERROR/AndroidRuntime(1149): Caused by: java.lang.IllegalStateException: get field slot from row 0 col 3 failed
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at android.database.CursorWindow.getBlob_native(Native Method)
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at android.database.CursorWindow.getBlob(CursorWindow.java:242)
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:35)
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at com.korn.pizzacounter.Main.onCreateDBAndDBTabled(Main.java:70)
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at com.korn.pizzacounter.Main.onCreate(Main.java:40)
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-30 12:16:26.755: ERROR/AndroidRuntime(1149): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)

最佳答案

数据库查询语句中缺少第四列。你只声明“name”、“rate”、“eattime”,而不声明“image”。

关于android - 非法状态异常 : get field slot from row 0 col 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7610252/

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