Problems with "onActivityResult" photo

I have a problem with the camera and in many cases, to take a picture and take it to ImageView, get an error.

java.lang.RuntimeException: Unable to resume activity {co.com.xxxx.xxxx/xxxx.xxxx.screens.formularioScreen}:
 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent
 { act=inline-data (has extras) }} to activity {xxxx.xxxx,screens/xxxx.xxxx.screens.formularioScreen}:
 java.lang.NullPointerException

My code for the photo:

    Button oButton = new Button(this);
    oButton.setText("take Photo");
    oButton.setOnClickListener(new OnClickListener() {              
        public void onClick(View v) {

            oImageActual = oView; //variable final = ImageView
            Intent intent =  new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, TAKE_PICTURE);
        }                       
    });

//layout = container
layout.addView(oButton);

and I have an onActivityResult method

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == TAKE_PICTURE) {          
        if (data != null) {             
            if (data.hasExtra("data")) {
                oImageActual.setImageBitmap((Bitmap) data.getParcelableExtra("data"));
            }               
        }
    }
}

Not if I miss any attempt / trick or something like that, but the error happens often.

Any ideas?


The error still appears, there are times when this is not the case, and others are.
Try to put it on oneilse14,

oImageActual.setImageBitmap((Bitmap) data.getExtras().get("data"));

but the error remained the same. Does anyone know why this is happening or how to prevent it?


Start the camera using the button

oButton.setText("Take photo");
oButton.setOnClickListener(new OnClickListener() {              
    public void onClick(View v) {       
        oImageActual = oView; //oImageActual ImageView is a final variable = new ImageVew(this);
        Intent intent =  new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                           
        startActivityForResult(intent, TAKE_PICTURE);
    }                       
});
LinAyout.addView(oButton);

And this is onActivityResult.

/**
 * Al terminar la actividad de la camara, se ejecuta este metodo para continuar
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);      
    if (requestCode == TAKE_PICTURE && (resultCode == Activity.RESULT_OK)) {            
        if (data != null) {         
            if (data.hasExtra("data")) {                
                oImageActual.setImageBitmap((Bitmap) data.getParcelableExtra("data"));
            }   
        }
    }
}
+3
source share
2 answers

startActivityForResult(intent, TAKE_PICTURE); . CameraActivity, . , , , , , .

+1

getParcelableExtra()

oImageActual.setImageBitmap((Bitmap) data.getExtras().get("data"));
0

All Articles