无法从CursorWindow读取第384行第47列的数据。请确保Cursor已正确初始化。

3

我正在读取来自Android日历的一些数据,有时候用户会报告一些奇怪的崩溃,例如:

java.lang.IllegalStateException: Couldn't read row 384, col 47 from CursorWindow. 
Make sure the Cursor is initialized correctly before accessing data from it.

这是我的代码(粗体字是应用程序崩溃的行):

        Cursor eventCursor = contentResolver.query
            (builder.build(), 
            null, 
            CalendarContract.Instances.CALENDAR_ID + " IN (" + ids  + ")", 
            null, 
            null);

        if (eventCursor == null)
            return true;

        while (eventCursor.moveToNext()) {  //this line causecrash
            ... do something...
        }

为什么会发生这种情况?它无法模拟。我从未遇到过这种情况,也无法理解错误的原因和提示信息。
1个回答

0
在你的迭代开始时,使用 eventCursor.moveToFirst() 将光标移动到第一行。你可以像这样使用:
if (eventCursor != null) {

    //Start from beginning
    eventCursor.moveToFirst();

    // Loop over rows
    while (eventCursor.moveToNext()) {

        // Do Somehing here
    }
 }

您还可以通过使用 eventCursor.getCount() 来检查光标是否有行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接