Why the cursor null?

2019-08-19 07:59发布

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条回答
ら.Afraid
2楼-- · 2019-08-19 08:28

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();
} 
查看更多
登录 后发表回答