【问题标题】:Failed delivering result info [ null pointer exception ] CameraIntent android传递结果信息失败 [空指针异常] CameraIntent android
【发布时间】:2014-03-25 10:42:29
【问题描述】:

我开发了一个应用程序,该应用程序通过相机拍照并裁剪并在 imageview 中显示,还将数据保存到数据库中。我在 onActivityResult 中收到以下错误

这里是Logcat 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);
    }

【问题讨论】:

  • 请复制您的LogCat 并粘贴到问题中。
  • 我无法发布完整错误。请看屏幕截图...
  • 您的屏幕截图未显示完整的日志。
  • 错误出现在“Log.v("picUri", picUri.toString());"在 com.android.project.birthdayreminder.ContactInfoMoreOption.onActivityResult(ContactInfoMoreOption.java:795)
  • picUri的类型是什么?

标签: android


【解决方案1】:

我假设您正在尝试从Intent data 中提取Bitmap...如果我的假设是正确的,那么您可以尝试如下...

Bundle pictureExtra = intent.getExtras();
Bitmap bitmap = (Bitmap) pictureExtra.get("data");

更新:

你可以看看这些链接:

Android - Problem getting image uri

Android ACTION_IMAGE_CAPTURE Intent

【讨论】:

  • 我从 CameraIntent 获取返回数据的 Uri,然后将它们传递给裁剪活动。我在返回的 Uri 中收到 NULLPOINTER 错误
  • 在我的答案中查看给定的答案链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-23
  • 1970-01-01
  • 1970-01-01
  • 2014-11-03
  • 2013-10-01
  • 2012-04-07
  • 1970-01-01
相关资源
最近更新 更多