Why the cursor null?

旧巷老猫 提交于 2019-12-12 04:45:41

问题


First, I use below ode to get all image path. And save to string array path.

String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.DATA};  
Cursor cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Media._ID); 
int count = cursor.getCount();
int image_column_index = cursor.getColumnIndex(MediaStore.Images.Media._ID); 
int image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
int i;
for(i = 0; i < count; i++) {
cursor.moveToPosition(i);
int id = cursor.getInt(image_column_index);
pat[i[ = cursor.getString(image_path_index);
}

After finish, I try below code to get thumbnail.

int i;
for(i = 0; i < count; i++) {
String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA};  
            Cursor cursor = act.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, MediaStore.Images.Media.DATA + "=?", new String[] {path[i]}, MediaStore.Images.Media._ID); }

But while the file number very large(about 1000 files), the cursor show null. I confirm it not cause by path name. Any other reason?


回答1:


The second try add cursor.close(); As below:

int i; 
for(i = 0; i < count; i++) { 
String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA};               
Cursor cursor = act.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, MediaStore.Images.Media.DATA + "=?", new String[] {path[i]}, MediaStore.Images.Media._ID); 
cursor.close();
} 


来源:https://stackoverflow.com/questions/9426170/why-the-cursor-null

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