【发布时间】:2018-06-02 09:47:37
【问题描述】:
我有一个程序允许用户从图库中挑选图像,将其保存在数据库中并显示在屏幕上。这适用于大多数图像,但对于某些图像,应用程序会崩溃。 Logcat 中没有错误消息。但是当我重新启动应用程序时,我收到一条错误消息:
无法从 CursorWindow 读取第 0 行第 1 列。确保 Cursor 在从中访问数据之前已正确初始化。
(在 ANDROID SDK 24 上测试)
new AlertDialog.Builder(this).setTitle("Take or Pick?").setMessage("Choose to click a new picture or choose from existing").
setNegativeButton("CHOOSE PHOTO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQUEST_IMAGE_PICKER);
}
}).create().show();
onActivityResult 代码如下:
if (requestCode == REQUEST_IMAGE_PICKER && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
Bitmap bmp= null;
try { //GET BITMAP FROM URI , TRY CATCH USED TO TACKLE
bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage)); // IO STREAM FILE NOT FOUND ERROR
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(cameraTeamStatus==1) {
img1.setImageBitmap(bmp); //SET IMAGE
image1_to_save = convertToBlob(bmp); //CONVERT TO BLOB
}
【问题讨论】:
-
我在您的代码中没有看到 CursorWindow::我认为这次崩溃是由于相机拍摄的图片尺寸较大且光标无法处理并且光标初始化失败。
-
那么使用光标窗口是否有助于解决问题?
-
你试过用相同的格式但图片尺寸更小吗?
-
是的,当图像尺寸较小时,应用程序运行良好
标签: android android-intent android-gallery android-camera-intent