android sqlist中游标下标越界问题解决方案

发布时间:2020-08-10 21:36:02 作者:King灵
来源:网络 阅读:783

在使用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个位置。

推荐阅读:
  1. Unity3D在Android编辑模式下使用lightmap
  2. Android实现倾斜角标样式的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

查询 android 越界

上一篇:asp.net c# 删除弹出提示框

下一篇:如何计算MySQL QPS和TPS的值

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》