zoukankan      html  css  js  c++  java
  • android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5

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

  • 相关阅读:
    Https的请求过程
    计算机网络知识
    数据结构之图
    Python3线程池进程池
    数据结构之堆heapq
    EffectivePython并发及并行
    EffectivePython类与继承
    EffectivePython并发及并行
    5.19完全数
    5.18数字全排列
  • 原文地址:https://www.cnblogs.com/xiaxiaoping/p/3407774.html
Copyright © 2011-2022 走看看