1月24日
作者:互联网
今天继续实现数据库操作
遇到模拟器 app keep stop
找了很久问题看日志和模拟器日志没有报错信息,
最后发现点击run的图标会有报错信息
java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.
该报错经过上网查证和自己检查发现是对数据库操作语句有误 如下
jilu.setJine(cursor.getString(0));
jilu.setQk(cursor.getString(1));
jilu.setTime(cursor.getString(2));
//这里的数字是new String[]{"jine","qk","time"}中的顺序,不是数据表中的顺序
jiluList.add(jilu);
public List<jilu> findall(){
//实例化数据库对象
SQLiteDatabase db=openHelper.getWritableDatabase();
Cursor cursor= db.query("jilu",new String[]{"jine","qk","time"},null,null,null,null,null);
//Cursor游标
List<jilu> jiluList =new ArrayList<>();
while (cursor.moveToNext()){
jilu jilu=new jilu();
jilu.setJine(cursor.getString(0));
jilu.setQk(cursor.getString(1));
jilu.setTime(cursor.getString(2));
//这里的数字是new String[]{"jine","qk","time"}中的顺序,不是数据表中的顺序
jiluList.add(jilu);
}
db.close();
return jiluList;
}
标签:24,getString,jilu,cursor,new,jiluList,null 来源: https://www.cnblogs.com/buyaoya-pingdao/p/14322393.html