在使用android的sqlist时,出现了以下错误
android.database.CursorIndexOutOfBoundsException: Index 14 requested, with a size of 14
经过排除,确定了错误位置
错误代码为
public ArrayList<receiveContext> query(String table_name,String[] arg)
{
SQLiteDatabase db=getWritableDatabase();
Cursor c = db.query(table_name,null,poster+"=?",arg,null,null,updateTime,null);//查询并获得游标
ArrayList<receiveContext> l=new ArrayList<receiveContext>();
if(c.moveToFirst())
{//判断游标是否为空
for(int i=0;i<c.getCount();i++){
c.moveToPosition(i);//正确语句
//c.move(i); //错误语句
String getContext="";
int getStyle = 0;
String getTime="";
getContext= c.getString(c.getColumnIndex(context));
getStyle =c.getInt(c.getColumnIndex(style));
getTime = c.getString(c.getColumnIndex(updateTime));
receiveContext rc=new receiveContext(getContext,getStyle,getTime);
l.add(rc);
}
}
c.close();
db.close();
return l;
}
这是我写的一个数据库查询的方法,越界原因是使用了方法c.move(i);这个方法我估计(有待考证)应该是当前指针+i,所以会导致越界。正确的方法应该是
c.moveToPosition(i);
这是跳到第i个位置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。