我的相机有问题,在很多情况下拍摄照片并将其带到 ImageView 时,会出错。
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
我的拍照代码如下:
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);
我有 onActivityResult 方法
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"));
}
}
}
}
如果我错过了一些尝试/捕捉或其他东西,但错误经常发生。
有任何想法吗?
错误仍然出现,有时它不会出现,而其他时候则如此。
尝试放置它 oneilse14 说,
oImageActual.setImageBitmap((Bitmap) data.getExtras().get("data"));
但错误保持不变。任何人都知道为什么会发生这种情况或如何防止它?
一键启动相机
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);
这就是 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"));
}
}
}
}