为什么光标为空? [英] Why the cursor null?
本文介绍了为什么光标为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先,我在ode下面使用所有图像路径。
并保存到字符串数组路径。
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); }
但是当文件号很大(大约1000个文件)时,光标显示为空。
我确认不是由路径名引起的。
还有其他原因吗?
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?
推荐答案
第二次尝试添加cursor.close();
如下:
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();
}
这篇关于为什么光标为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文