作业帮 > 综合 > 作业

android.database.CursorIndexOutOfBoundsException:Index 2 req

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/04/28 17:48:23
android.database.CursorIndexOutOfBoundsException:Index 2 requested,with a size of 2
查询方法:
\x05public Cursor priceQuery(String name)
\x05{
\x05\x05SQLiteDatabase db = DBHelper.getWritableDatabase();\x05
\x05\x05Cursor c = db.rawQuery("select market,price from "+"price"+" where goods = ;",new String[]{""+name});
\x05\x05return c;
\x05}
主程序:
\x05\x05DBAdapter db = new DBAdapter(this);
\x05\x05db.open();
\x05\x05\x05\x05
\x05\x05Cursor c = db.priceQuery(name);
\x05\x05c.moveToFirst();
\x05\x05while(c.moveToNext());
{
\x05HashMap map = new HashMap();
\x05\x05map.put("ItemTitle",c.getString(0));
\x05\x05map.put("ItemPrice",c.getString(1));
\x05\x05listItem.add(map);
}
\x05\x05
c.close();
db.close();
数组越界,while中的条件改一下就可以了
...
c.moveToFirst();
while(!c.isAfterLast())
{
 HashMap map = new HashMap();
 map.put("ItemTitle", c.getString(0));
 map.put("ItemPrice", c.getString(1));
 listItem.add(map);
c.moveToNext()
}
...