显示来自东方卡的图像给出了 java.lang.nulPointer 异常
我有这个片段可以从 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);}
我已经尝试了许多其他解决方案,但即使更改图像文件,我仍然遇到相同的问题。当我更改文件名以给出错误的文件名时,它告诉我找不到文件:(
任何人都可以帮忙吗?我看到其他人也有同样的问题,但没有看到任何适合我的解决方案
i have this snippet to retieve an image from an sd car card but all i get is 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);}
I have tried many oder solutions but still, i always have the same problem even when i change the image file. And when i change the file name to give a false one, it tells me that file not found :(
can anyone help?? i've seen others having the same problem but didn't see anysolution that worked for me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试过,这对我有用:
如果您有更多问题,您可能需要了解外部存储的状态:
I tried it and this works for me:
If you have more problems you may want to the state of the external storage: