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,睡觉了。

最新文章

  1. 06.SQLServer性能优化之---数据库级日记监控
  2. BootStrap_03之组件(手风琴、导航)
  3. MapReduce、Hbase接口API实践
  4. node Later定时任务
  5. xcode duplicate symbol _GAD_MD5 解决方法
  6. iOS 单元測试之XCTest具体解释(一)
  7. HDU 5889 Barricade
  8. JSP简单标签标签库开发
  9. docker网络访问(三)
  10. RobotFramework自动化测试框架-移动手机自动化测试Click A Point关键字的使用
  11. ROS_Kinetic_x 基於ROS和Gazebo的RoboCup中型組仿真系統(多機器人協作)
  12. CentOS 常用Linux命令
  13. 1K star+ 的项目是如何炼成的?
  14. zookeeper安装教程(zookeeper3.4.5为例)
  15. 一文看懂大数据的技术生态Hadoop, hive,spark都有了[转]
  16. Java数据类型Stack栈、Queue队列、数组队列和循环队列的比较
  17. [MySQL]查看用户权限与GRANT用法
  18. Groovy学习笔记(1)读取CSV文件
  19. SQLServer分页查询笔记
  20. 蓝牙disable流程简述

热门文章

  1. Dynamics CRM Form表单中通过javascript抓取触发change事件字段的属性名
  2. javascript语法之循环语句
  3. 学习pthreads,使用条件变量进行多线程之间的同步
  4. hadoop上C++开发两种方式的例子
  5. android重启代码
  6. Lucene 学习资料
  7. Leetcode_278_First Bad Version
  8. HBase多次加载-ROOT-和META的bug
  9. obj-c编程10:Foundation库中类的使用(4)[文件管理,查询当前进程信息]
  10. Which SQL statement is the trump card to the senior software developer