1

I have an object, called Object_Assoc, this object is supposed to store bitmap images into its member variable o_memory. I call the helper function setO_memory, with the bitmap image to set as the parameter. However this is crashing my application. I create the bitmap image, by using the android camera 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
pTurner
  • 11
  • 2
  • 1
    `However this is crashing my application` -> what is the error that is printed to your LogCat console? – Matt Clark Feb 25 '19 at 23:28
  • @MattClark 019-02-21 04:05:57.111 5658-5658/memorypalace.palace14 E/AndroidRuntime: FATAL EXCEPTION: main Process: memorypalace.palace14, PID: 5658 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 – pTurner Feb 25 '19 at 23:43
  • 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 – pTurner Feb 25 '19 at 23:43
  • Please paste that LogCat into the question, not in a comment, as it is too difficult to read! And `newObj` is null; please investigate that. – Ken Y-N Feb 25 '19 at 23:43
  • 1
    @KenY-N I think thats the issue, sure I'll paste that into the question. – pTurner Feb 26 '19 at 00:03

0 Answers0