【发布时间】:2015-12-03 17:30:19
【问题描述】:
我正在从我的应用中调用默认图库应用来选择任何照片。下面是我从图库中获取所选图像路径的代码。除少数照片外,所有照片都可以正常工作。当我从图库中选择任何 PICASA 上传的照片时,应用程序会强制关闭。请帮我。
在 onActivityResult()....
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String selectedPhotoPath = cursor.getString(columnIndex).trim(); <<--- NullPointerException here
cursor.close();
bitmap = BitmapFactory.decodeFile(selectedPhotoPath);
......
【问题讨论】:
-
它在哪一行给你一个 NPE?是 data.getData()!=null 吗?
-
columnIndex 为 0,String selectedPhotoPath = cursor.getString(columnIndex).trim();
标签: android cursor gallery uri