gpt4 book ai didi

java - 无法从 CursorWindow 读取第 384 行,第 47 列。确保正确初始化 Cursor

转载 作者:太空狗 更新时间:2023-10-29 15:10:57 24 4
gpt4 key购买 nike

我正在从 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...
}

为什么会这样?无法模拟。它从来没有发生在我身上,我只是无法理解原因和错误消息。

最佳答案

在迭代开始时使用 eventCursor.moveToFirst()移动到第一行。你可以使用这样的东西:

if (eventCursor != null) {

//Start from beginning
eventCursor.moveToFirst();

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

// Do Somehing here
}
}

您还可以使用 eventCursor.getCount() 检查 Cursor 是否有行。 .

关于java - 无法从 CursorWindow 读取第 384 行,第 47 列。确保正确初始化 Cursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16563934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com