Android 将图像从文件路径(SD卡)设置为imageview

Android 将图像从文件路径(SD卡)设置为imageview,android,imageview,Android,Imageview,我正在尝试使用保存的路径设置ImageView的背景。但是,以下代码崩溃 selectSavedImagefromGallery(imagePath); 此处imagePath=“/storage/sdcard0/Downloads/image.jpg”,这是一个有效路径。当我从图库中选择图像时,它会起作用。但我想保存路径,以便随时使用 private void selectSavedImagefromGallery(String savedImagePath) { Bitmap b

我正在尝试使用保存的路径设置ImageView的背景。但是,以下代码崩溃

selectSavedImagefromGallery(imagePath);
此处imagePath=“/storage/sdcard0/Downloads/image.jpg”,这是一个有效路径。当我从图库中选择图像时,它会起作用。但我想保存路径,以便随时使用

private void selectSavedImagefromGallery(String savedImagePath) {

    Bitmap bm;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(savedImagePath, options);
    final int REQUIRED_SIZE = 200;
    int scale = 1;

    while (options.outWidth / scale / 2 >= REQUIRED_SIZE
            && options.outHeight / scale / 2 >= REQUIRED_SIZE)
        scale *= 2;
    options.inSampleSize = scale;
    options.inJustDecodeBounds = false;
    bm = BitmapFactory.decodeFile(savedImagePath, options);

    profile_pic.setImageBitmap(bm);
}
此错误是由最后一行引起的:

profile_pic.setImageBitmap(bm);
我能做些什么使它工作


谢谢。

“但是下面的代码会崩溃”——使用LogCat检查与崩溃相关的Java堆栈跟踪:我想我理解它崩溃的原因。这是因为没有向该方法发送意图(与我从图库中拾取图像时不同)。我只是不知道怎么修。