0

In my application I am trying to add a photo by bringing up the camera so that the user can add the photo they want. Then after taking the picture a custom dialog comes up to make sure that that was the picture they wanted. As of now after the picture is taken and accepted the camera stops. Here is my code (the bitmap is initialized outside of everything) and the error...

 public void pictureDialog()
    {
        Button picAdd;
        Button picCancel;
        ImageView imageView;
        final Dialog customDialog = new Dialog(this);

        picAdd = (Button) findViewById(R.id.picAdd);
        picCancel = (Button) findViewById(R.id.picCancel);
        imageView = (ImageView) findViewById(R.id.imageView);

        customDialog.setContentView(R.layout.picture);
        customDialog.setTitle("Add Picture");
        if (cameraImage != null)
        {
            imageView.setImageBitmap(cameraImage);

            picAdd.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {

                }
            });
            picCancel.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {

                }
            });
            customDialog.show();
        }

    }

    public void camera()
    {
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(cameraIntent, CAMERA_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK)
        {
            if (requestCode == CAMERA_CODE)
            {
                cameraImage = (Bitmap) data.getExtras().get("data");
                pictureDialog();
            }
        }
    }

error

07-24 12:24:38.393  17706-17706/com.customledsupply.ledaudit E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.customledsupply.ledaudit, PID: 17706
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.customledsupply.ledaudit/com.customledsupply.ledaudit.FixtureDescription}: 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:3577)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3620)
            at android.app.ActivityThread.access$1300(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
            at com.customledsupply.ledaudit.FixtureDescription.pictureDialog(FixtureDescription.java:126)
            at com.customledsupply.ledaudit.FixtureDescription.onActivityResult(FixtureDescription.java:164)
            at android.app.Activity.dispatchActivityResult(Activity.java:6192)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3573)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3620)
            at android.app.ActivityThread.access$1300(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
JJ Stamp
  • 121
  • 2
  • 13

1 Answers1

1

The problem is, that Camera Intent return NULL. You have to check this: onActivityResult returned from a camera, Intent null

It is not described in Android documentation.

Community
  • 1
  • 1
Eliasz Kubala
  • 3,836
  • 1
  • 23
  • 28
  • Are you pointing me towards all the answers or one specifically? – JJ Stamp Jul 26 '15 at 23:56
  • In the getImageUri() function I am having errors show up on the `CustomException` and `File.getPath()` where they show up red and I don't know why, any help? – JJ Stamp Jul 27 '15 at 18:41