Android 将结果ResultInfo{who=null,request=0,result=0,data=Intent{}}传递到活动java.lang.NullPointerException失败
这是我为在应用程序中打开gallery和camera而编写的代码。在未设置的情况下按back B按钮时,应用程序崩溃 形象。给我建议解决办法Android 将结果ResultInfo{who=null,request=0,result=0,data=Intent{}}传递到活动java.lang.NullPointerException失败,android,nullpointerexception,imageview,android-camera,image-gallery,Android,Nullpointerexception,Imageview,Android Camera,Image Gallery,这是我为在应用程序中打开gallery和camera而编写的代码。在未设置的情况下按back B按钮时,应用程序崩溃 形象。给我建议解决办法 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (reque
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == RESULT_OK) {
if (data != null) {
// this is image view where you want to setimage
bmp = (Bitmap) data.getExtras().get("data");
ivKidsProfilePicture.setImageBitmap(bmp);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, baos);
childpic = baos.toByteArray();
Log.d("camera ---- > ", "" + data.getExtras().get("data"));
}
masterDatabaseAdapter.insertProfilePicture(childpic);
}
else {
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]);
String filePath = cursor.getString(columnIndex);
cursor.close();
if (bmp != null && !bmp.isRecycled()) {
bmp = null;
}
bmp = BitmapFactory.decodeFile(filePath);
ivKidsProfilePicture.setBackgroundResource(0);
ivKidsProfilePicture.setImageBitmap(bmp);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, baos);
childpic = baos.toByteArray();
}
masterDatabaseAdapter.insertProfilePicture(childpic);
}
if(requestCode==0&&resultCode==RESULT\u OK)的else分支出现问题-如果requestCode不是0或者RESULT\u OK(没有照片| | |回按),您仍然希望获取图像。但是解决方法是什么?在else分支中,不要尝试获取图片。或者检查空值,例如如果(data!=null){Uri selectedImage=data.getData();如果(selectedImage!=null){…}我已经尝试过了,但仍然不起作用。请建议一些其他代码。请指出它崩溃的地方。您是否从else分支中删除了所有代码,但它仍然不起作用?