Cursor c = db.query("user",null,null,null,null,null,null);//查询并获得游标
if(c.moveToFirst()){//判断游标是否为空
    for(int i=0;i<c.getCount();i++){
        c.move(i);//移动到指定记录
        String username = c.getString(c.getColumnIndex("username");
        String password = c.getString(c.getColumnIndex("password"));
    }
}

在通过以上代码读取sqlite user表中多条数据时,就会发生错误:android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5。我把上面代码改成以下:

Cursor c = db.query("user",null,null,null,null,null,null);//查询并获得游标

    for(int i=0;i<c.getCount() && c!=null ;i++){
if(c.moveToFirst()){//判断游标是否为空
        c.move(i);//移动到指定记录
        String username = c.getString(c.getColumnIndex("username");
        String password = c.getString(c.getColumnIndex("password"));
    }
}

OK,睡觉了。

android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5的更多相关文章

  1. android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3

           今天在写一个小项目的数据库部分的功能时,出现了一个这样的问题:java.lang.RuntimeException: Failure delivering result ResultIn ...

  2. android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1(zz)

    android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1 http://blog.cs ...

  3. Android android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1

    Android中数据库处理使用cursor时,游标不是放在为0的下标,而是放在为-1的下标处开始的. 也就是说返回给cursor查询结果时,不能够马上从cursor中提取值. 下面的代码会返回错误 U ...

  4. android.database.CursorIndexOutOfBoundsException: Index <m> requested, with a size of <n>

    遇到这样的问题比较郁闷,造成上述问题的原因也是多种多样的. 总结一下原因: 1:得到cursor对象,没有moveToPosition()或者moveToNext()等游标操作就进行cursor.ge ...

  5. Android开发7——android.database.CursorIndexOutOfBoundsException:Index -1 requested

    android中数据库处理使用cursor时,游标不是放在为0的下标,而是放在为-1的下标处开始的. 也就是说返回给cursor查询结果时,不能够马上从cursor中提取值. 下面的代码会返回错误Us ...

  6. Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常

    异常: Android.Database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 10 此错误是数据返回 ...

  7. 再读Android sqlite

    再读Android sqlite Android原生支持sqlite数据库操作,sqlite时轻量级关系型数据库,支持标准sql语句.Android对sqlite进行良好的接口封装来避免sql注入等安 ...

  8. Android多线程操作sqlite(Sqlite解决database locked问题)

    参考http://blog.csdn.net/sdsxleon/article/details/18259973  很好 https://github.com/2point0/Android-Data ...

  9. android 读取SQLite android could not open the database in read/write mode错误

    由于AndroidManifest.xml文件中uses-permission没有设置权限问题 <uses-permission android:name="android.permi ...

随机推荐

  1. “基于数据仓库的广东省高速公路一张网过渡期通行数据及异常分析系统"已被《计算机时代》录用

       今天收到<计算机时代>编辑部寄来的稿件录用通知,本人撰写的论文"基于数据仓库的广东省高速公路一张网过渡期通行数据及异常分析系统",已被<计算机时代>录 ...

  2. nginx 安装php

    1. 安装PHP 5.5.0 下载   1 2 cd /usr/local/src/ wget http://www.php.net/get/php-5.5.0.tar.bz2/from/jp1.ph ...

  3. Java 开源Wiki:XWiki

    XWiki是一个由Java编写的基于LGPL协议发布的开源wiki和应用平台.之前只接触过MediaWiki,但是MediaWiki是用PHP写的,一直想找找看有没有熟悉的JAVA语言的Wiki系统. ...

  4. 《java入门第一季》之Arrays类

    前面介绍了排序问题(见博客http://blog.csdn.net/qq_32059827/article/details/51362390):二分查找问题(见博客http://blog.csdn.n ...

  5. 基于web的jfreechart的使用

    这个模块的主要步骤就是: 前台通过struts调用后台,通过JFreeChart产生图片格式的图表,存储在某个位置,然后前台jsp再去调用图片. 来开工. JFreeChart的简介大家请百度. 首先 ...

  6. 11_Eclipse中演示Git版本的创建,历史版本的修改,创建分支,合并历史版本和当前版本

     1 执行以下案例: 某研发团队2011年初开发了一款名为Apollo的信息系统,目前已发布v1.0版本.此项目初期已有部分基础代码, 研发团队再此基础代码上经过3个月的努力发布了一个功能相对完备 ...

  7. STL算法设计理念 - 谓词,一元谓词demo

    谓词: 一元函数对象:函数参数1个: 二元函数对象:函数参数2个: 一元谓词 函数参数1个,函数返回值是bool类型,可以作为一个判断式 谓词可以使一个仿函数,也可以是一个回调函数. demo 一元谓 ...

  8. Android下VideoView的研究

    VideoView继承自SurfaceView,实现了MediaController.MediaPlayerControl的接口.在android系统中的包名为android.widget.Video ...

  9. SpriteBuilder中CCB精灵对象的Sprite frame为什么有时候不能修改

    有时候你会发现CCB中的精灵对象(root节点)的Sprite frame是灰色的,不能修改.因为它是根对象,所以不存在被嵌入其他CCB的情况,那到底是什么原因呢? 可以发现此时的Timeline当前 ...

  10. Java-HttpServlet

    /** * * Provides an abstract class to be subclassed to create * an HTTP servlet suitable for a Web s ...