android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
来源:互联网 发布:淘宝店铺装修怎么做 编辑:程序博客网 时间:2024/05/16 05:50
01-02 00:13:43.380: E/flyLog:ChatManager(963): getUnreadChatGroupandroid.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
01-02 00:13:43.380: E/flyLog:ChatManager(963): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
01-02 00:13:43.380: E/flyLog:ChatManager(963): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
01-02 00:13:43.380: E/flyLog:ChatManager(963): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
我的代码是这样的:
<span style="white-space:pre"></span>cursor = db.rawQuery("select id,group_name,group_type from chat_group g where group_type in( "+p.toString()+" ) and exists(select 1 from user_chat_unreads c where c.group_id=g.id and c.status=0 and c.user_id=? ) order by last_time desc;", params);if(cursor.moveToFirst()){for (int i = 0; i < cursor.getCount(); i++) {cursor.move(i);ChatGroup chatGroup = new ChatGroup();String id = cursor.getString(0);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}
cursor.move是从网上拷贝过来的,并且网上都说这样取的,看不出来问题,仔细debug也没发现代码问题,于是看官方API,
Move the cursor by a relative amount, forward or backward, from the current position. Positive offsets move forwards, negative offsets move backwards. If the final position is outside of the bounds of the result set then the resultant position will be pinned to -1 or count() depending on whether the value is off the front or end of the set, respectively.
This method will return true if the requested destination was reachable, otherwise, it returns false. For example, if the cursor is at currently on the second entry in the result set and move(-5) is called, the position will be pinned at -1, and false will be returned.
意思是Cursor的move(i)的i是移动相对量,即相对于当前值向前或向后移动i个,i是正的就向后移动,i是负数就向前移动
我勒个去
果断改成moveToPosition(int position) ,果然好了,看来不能尽信网,不然不如无网
或参考其他方法改变代码处理方式:moveToNext()
相当于move(1)
moveToPrevious()
相当于move(-1)
- android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
- Android开发7——android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index <m> requested, with a size of <n>
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2
- qlite操作时出现下面错误 android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 14
- android.database.CursorIndexOutOfBoundsExcept: Index -1 requested, with a size of 1
- cursor使用错误(android.database.CursorIndexOutOfBoundsException: Index -1 requested)
- 单例模式
- Nexus usage experience
- 基于Devstack 开发环境下Reboot Host之后的各个服务的启动过程
- 手把手教你把Vim改装成一个IDE编程环境(图文)
- linux与宿主机配置
- android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
- IT人不要一辈子靠技术
- 【Scala学习笔记】类型参数化数组
- 在Linux下,一个文件也有三种时间,分别是:访问时间、修改时间、状态改动时间
- Subversion的下载和安装
- GPIO的驱动模型
- 面向对象(对象的内存体现)
- 推荐一个入门级linux等知识学习的youtube视频站
- Windows 7下安装python recommender Crab步骤