Why the cursor null?
Asked Answered
B

1

0

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?

Beezer answered 24/2, 2012 at 6:2 Comment(1)
can you post full class code, or are you getting any exception in logs, other than null pointerVaginate
A
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();
} 
Actress answered 29/2, 2012 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.