android 读取数据库问题

skywxx 发布于 2012/08/15 10:54
阅读 2K+
收藏 0
if(c.moveToFirst()){ 
	for (int i=0 ; i<c.getCount();i++){
		c.move(i);
		String id = c.getString(c.getColumnIndex("_id"));
		String price = c.getString(c.getColumnIndex("price"));
		String name = c.getString(c.getColumnIndex("name"));

		CheckMenu cm = new CheckMenu();
		cm.setId(id);
		cm.setPrice(price);
		cm.setName(name);

		list.add(cm); 
			}

数据库中存放了三条数据,执行时报错Unable to start activity ComponentInfo{com.wxx.wlo/com.wxx.wlo.UpdateActivity}: android.database.CursorIndexOutOfBoundsException: Index 3 requested, with a size of 3

以下是问题补充:

@skywxx:怎样修改? (2012/08/15 10:54)
加载中
0
z
zhangQ

while(!c.isAfterLast){

String id = c.getString(c.getColumnIndex("_id"));

String price = c.getString(c.getColumnIndex("price"));

String name = c.getString(c.getColumnIndex("name"));
          CheckMenu cm = new CheckMenu();
          cm.setId(id);

          cm.setPrice(price);

          cm.setName(name);

          

list.add(cm);

 c.moveToNext();

}

skywxx
skywxx
谢谢了,虽然已经解决了,但是你的方法很不错
返回顶部
顶部