0
votes

I've got following error from some user.

Couldn't read row 34, col 11 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

This issue happende in follwoing line:

@Override
    public void bindView(final Context context, Cursor MessageCursor, int position) {

        final MessageEntity messageEntity = MessageDataSource.cursorToMessage(MessageCursor);

       // more code
     }

and cursorToMessage is:

public static MessageEntity cursorToMessage(Cursor cursor) {
        MessageEntity.Builder builder = new MessageEntity.Builder();
        builder.setId(cursor.getLong(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_ID)))
                .setMessageId(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_MESSAGE_ID)))
                .setJabberId(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_JID)))
                .setContactUsername(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_CONTACT_USERNAME)))
                .setText(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_TEXT)))
                .setType(MessageEntity.Type.getEnum(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_TYPE))))
                .setTimestamp(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_TIMESTAMP)))
                .setDeliveryStatus(MessageEntity.DeliveryStatus.getEnum(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_STATUS))))
                .setUnread((cursor.getInt(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_UNREAD)) > 0))
                .setOutgoing((cursor.getInt(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_OUTGOING)) > 0))
                .setThumbnail(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_THUMBNAIL)))
                .setJsonData(cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.COLUMN_EXTRA_DATA)));

        return builder.build();
    }

I've search a lot in SO but other problem is like Couldn't read row -1 or Couldn't read column -1 that it's caused when you don't call moveToFirst() or you don't have one column. as this problem happened for some user i can't detect why this happened. did you have any idea.

if you want more info or more code tell me. Thanks in advance.

Edit

My projection is null and i have all columns. this problem not happened for all user.

Update

My problem is outOfMemory, as i catch that exception in one place in my project, application crashed in some where else.

2

2 Answers

1
votes

Don't store large data in an Android SQLite database. The CursorWindow can only hold 2MB of data, any row larger than that will cause an error like this.

In particular, the COLUMN_THUMBNAIL seems to be the culprit. Instead of storing image data in the database, store images in the filesystem and just store the path in database.

For reference, the exception gets thrown whenever CursorWindow::getFieldSlot() returns NULL. Out-of-bounds indices are a common reason for that, but that isn't the case with you - both the row and column numbers are valid. Full cursor window is another reason.

0
votes

I'm quite sure you forgot to add the column to the projection or that you did not call moveToFirst() in the beginning.