将位图图像存储到对象Anroid

时间:2019-02-25 23:27:15

标签: java android xml

我有一个对象,称为Object_Assoc,该对象应该将位图图像存储到其成员变量o_memory中。我调用辅助函数setO_memory,并将位图图像设置为参数。但是,这使我的应用程序崩溃。我使用Android相机API创建位图图像。

public void takePicture(View view) {
    Intent imageTakeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (imageTakeIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(imageTakeIntent, REQUEST_IMAGE_CAPTURE);
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");

        // Need to set image of Object here to object.

        newObj.setO_memory(imageBitmap);

        setContentView(R.layout.view_existing_obj_pop_up);

        final ImageView mImageView = findViewById(R.id.clickedObjImage);

        // Write object to Palace File
        listOfMyPalaces.writePalacesFile(MyPalaceDetail.this);

        // Set image
        mImageView.setImageBitmap(imageBitmap);

        // Sets the current view back to the palace detail(Unsuccessful though)
        setContentView(R.layout.activity_my_palace_detail);

        // Resets the Dialog to include the image that has been taken with the camera
        init();
        initDraggingListening();
    }
}
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=101, result=-1, data=Intent { act=inline-data (has extras) }} to activity {memorypalace.palace14/memorypalace.palace14.MyPalaceDetail}: java.lang.NullPointerException: Attempt to invoke virtual method 'void memorypalace.palace14.classes.Object_assoc.setO_memory(android.graphics.Bitmap)' on a null object reference

0 个答案:

没有答案
相关问题