我正在开发一个通过相机拍照并裁剪它并在imageview中显示它的应用程序也将数据保存到数据库中。我在onActivityResult
中收到以下错误这是Logcat ERROR!
的 的 * ERROR ***
将结果ResultInfo {who = null,request = 0,result = -1,data = Intent {act = inline-data(has extras)}}传递给活动{com.android.project.birthdayreminder / com.android .project.birthdayreminder.ContactInfoMoreOption}:java.lang.NullPointerException
CameraActivity.java
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(captureIntent, CAMERA_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_REQUEST) {
if (resultCode==RESULT_OK) {
picUri = data.getData();
Log.v("picUri", picUri.toString());
performCrop();
}
}
else if (requestCode==PICK_CROP) {
if (resultCode==RESULT_OK) {
View view=getLayoutInflater().inflate(R.layout.list_row,null);
ImageView imgView=(ImageView)view.findViewById(R.id.list_image);
Bundle extras = data.getExtras();
Bitmap bitmap = extras.getParcelable("data");
byte bitObj[]=BirthdayCalculation.convertImageToByte(bitmap);
Log.v("Photo byte.......", bitObj.toString());
ContentValues values=new ContentValues();
values.put(BirthdayProvider.PHOTO, bitObj);
int count=getContentResolver().update(BirthdayProvider.CONTENT_URI, values, BirthdayProvider.NUMBER+"='"+SearchListActivity.longClickValue+"'", null);
if (count==1) {
finish();
imgView.setImageBitmap(bitmap);
//bitmap=BitmapFactory.decodeByteArray(bitObj, 0, bitObj.length);
//imgView.setScaleType(ScaleType.FIT_XY);
Toast.makeText(getBaseContext(),"Updated Successfully",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getBaseContext(),"Updation Failed",Toast.LENGTH_SHORT).show();
}
}
}
}
}
public void performCrop(){
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PICK_CROP);
}
答案 0 :(得分:0)
我假设你试图从Bitmap
中提取Intent data
...如果我的假设是真的那么你可以尝试如下...
Bundle pictureExtra = intent.getExtras();
Bitmap bitmap = (Bitmap) pictureExtra.get("data");
<强>更新强>
您可以查看以下链接: