0

嗨,大家好,

我正在尝试从保管箱“相机上传”文件夹中获取图像并将该图像设置为 android 中的图像视图但应用程序强制突然关闭,我能够从 sd 卡和相机获取图像并能够将该图像设置为 ImageView,但我的下一个需要是从保管箱中获取图像并将其设置为 ImageView,但它对我不起作用,如果有人知道如何解决此问题,请帮助我解决此问题。

我的代码如下:

我添加了微调器以从图库、相机和保管箱中选择图像,我可以从图库和照相机中获取图像,但不能从保管箱中获取图像,请帮助解决此问题:

Error showing as fatal exception 
Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent
 { dat=file:///mnt/sdcard/Android/data/com.dropbox.android/files/scratch/Camera Uploads/2013-11-11 09.42.20.jpg typ=image/jpeg }} to activity {com.capstone.classitweetsdemo/com.capstone.classitweetsdemo.MainActivity}: java.lang.NullPointerException

提前致谢。

spnImage.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

        if (spnImage.getSelectedItem().toString().equals("Select from Gallery")) {

            imageLayout.setVisibility(View.VISIBLE);

            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select image to upload."), RESULT_LOAD_IMAGE);
        } else if (spnImage.getSelectedItem().toString().equals("Capture Image")) {

            imageLayout.setVisibility(View.VISIBLE);

            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            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]);
            picturePath = cursor.getString(columnIndex);
            cursor.close();

            imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

            sldImgPic.setImageBitmap(BitmapFactory.decodeFile(picturePath));
        } else if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
            photo = (Bitmap) data.getExtras().get("data");
            imageView.setImageBitmap(photo);
        }
    }
}
4

1 回答 1

0

//mnt/sdcard/Android/data是每个app的私有空间,不能从这个空间获取文件

于 2013-11-11T09:58:03.847 回答