cursorindexoutofboundsException: After last row 分析

最近遇到了 一个异常

cursorindexoutofboundsExceptio: After last row

字面意思已经很直白了,cursor已经被移到最后一行的后面,无法进行有效查询

网上大部分的建议是 : 添加 moveTofirst()方法

那么有没有可能是其他原因,我们需要从这个exception的源码入手


    /**
     * Gets value at the given column for the current row.
     */
    private Object get(int column) {
        if (column < 0 || column >= columnCount) {
            throw new CursorIndexOutOfBoundsException("Requested column: "
                    + column + ", # of columns: " +  columnCount);
        }
        if (mPos < 0) {
            throw new CursorIndexOutOfBoundsException("Before first row.");
        }
        if (mPos >= rowCount) {
            throw new CursorIndexOutOfBoundsException("After last row.");
        }
        return data[mPos * columnCount + column];
    }

源码中的mPos 是指第几行的意思 rowCount 就是cursor查询结果的总行数,这里的mPos在查询第一行时,取得的值为0

在反复打印数据后,错误只能定位到provider被kill

看来问题复杂了...

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值