Android cursor Error : Make sure the Cursor is initialized correctly before accessing data from it

给你一囗甜甜゛ 提交于 2019-12-03 21:50:56

The error message says

Failed to read row 0, column 1 from a CursorWindow which has 0 rows, 4 columns.

So your query is returning 0 rows. Your if statement should read:

if(cur!=null){
    // Best to manage any non-null cursor as then it will be closed when the
    // activity is stopped
    startManagingCursor(cur);
    // Only if a row was found
    if(cur.moveToFirst()) {
        Log.d("debug Cursor" , "can be created");
        Log.d("KEY_PHOTO_HKID_HEX" , cur.getString(1));
        Log.d("KEY_PHOTO_ADDRESS_HEX" , cur.getString(2));
        Log.d("KEY_PHOTO_BANK_HEX" , cur.getString(3));
    }else{
        // Handle no rows returned
    }
}else{
    Log.d("debug Cursor" , "cannot be created");
}

When query,each row of the CursorWindow is limited to 2097152. The size is set by com.android.internal.R.integer.config_cursorWindowSize.And you can find config_cursorWindowSize at https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/config.xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!