Java 将捕获图像数据插入片段中的ImageView时出错
我想将设备摄像头中的照片显示到图像视图中,我以前使用“活动”进行过此操作,但在片段上尝试时发现了此问题:Java 将捕获图像数据插入片段中的ImageView时出错,java,android,Java,Android,我想将设备摄像头中的照片显示到图像视图中,我以前使用“活动”进行过此操作,但在片段上尝试时发现了此问题: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.uhf/com.example.uhf.ac
java.lang.RuntimeException: Failure delivering result
ResultInfo{who=null, request=1888, result=-1, data=Intent {
act=inline-data (has extras) }} to activity
{com.example.uhf/com.example.uhf.activity.UHFMainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a
null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4295)
我的代码太简单了:
ImageView person_photo;
private static final int CAMERA_REQUEST = 1888;
Button open_camera = (Button)getView().findViewById(R.id.take_photo);
open_camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,CAMERA_REQUEST);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode != RESULT_CANCELED){
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
person_photo.setImageBitmap(photo);
}
}
}
获取person_图像视图的引用
person_photo= (ImageView)findViewById(R.id.person_photo_id);
我希望能成功 很抱歉,ofc我得到了我的图像的参考。我会编辑我的qstYup谢谢老兄当我编辑我的qst时我发现实际上我错过了声明soo U right再次感谢。