gpt4 book ai didi

android - 显示来自外部卡的图像给出 java.lang.nullPointerException

转载 作者:行者123 更新时间:2023-11-30 04:20:26 26 4
gpt4 key购买 nike

我有这段代码可以从 SD 汽车卡中获取图像,但我得到的只是 java.lang.nullPointerException:

try {

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 2;
options.inTempStorage = new byte[16*1024];
options.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().toString() + "/monImage.png", options);
image.setImageBitmap(bitmap);

// selected_photo = (ImageView) findViewById(R.id.selected_photo);
/*String photoPath="/"+ Environment.getExternalStorageDirectory().toString() + "/monImage.png";
Uri photoUri = Uri.parse(photoPath);
image.setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(),photoUri));*/


}
catch (Exception e){Log.d("merde>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "grrrrr " +e);}

我已经尝试了很多其他解决方案,但即使我更改了图像文件,我仍然遇到同样的问题。当我更改文件名以给出一个错误的文件名时,它告诉我找不到文件:(

谁能帮忙??我见过其他人遇到同样的问题,但没有看到任何对我有用的解决方案

最佳答案

我试过了,这对我有用:

Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/monImage.png");

如果您有更多问题,您可能需要了解外部存储的状态:

boolean mExternalStorageAvailable, mExternalStorageWriteable;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state))
{ mExternalStorageAvailable = true;
mExternalStorageWriteable = true;
}
else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
{ mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
}
else
{ mExternalStorageAvailable = false;
mExternalStorageWriteable = false;
}

关于android - 显示来自外部卡的图像给出 java.lang.nullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9337907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com