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 mar

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 23:42:18
android.database.CursorIndexOutOfBoundsException:Index2requested,withasizeof2查询方法:\x05publicCursorpr

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 mar
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();

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 mar
数组越界,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()
}
...