title: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { }} to activity
body: <p>I have a method that gives users the option to use the camera intent to capture a photo to then upload to the application:</p>
  
  <pre><code>public void UploadImageToFeed() {
  
          CharSequence colors[] = new CharSequence[] {"Gallery", "Take a Picture"};
  
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("Upload an Image");
          builder.setIcon(R.drawable.ic_upload_image);
          builder.setItems(colors, (dialog, which) -&gt; {
              if (which == 0) {
                  Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                  photoPickerIntent.setType("image/*");
                  startActivityForResult(photoPickerIntent, SELECT_PHOTO);
              } else {
                  Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  File file = new File(Environment.getExternalStorageDirectory(), "camera.jpg");
                  Uri uri = Uri.fromFile(file);
                  captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                  startActivityForResult(captureIntent, SELECT_PHOTO);
              }
          });
          builder.show();
  
      }
  </code></pre>
  
  <p>When a camera image is taken, I process the image to reduce its size before it is actually uploaded. This is where I get a crash.</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
          super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
  
          switch (requestCode) {
              case SELECT_PHOTO:
                  if (resultCode == RESULT_OK) {
  
                      ImageView imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
                      imageToUpload.setVisibility(View.VISIBLE);
  
                      Uri selectedImage = imageReturnedIntent.getData();
                      InputStream imageStream = null;
                      try {
                          imageStream = getContentResolver().openInputStream(selectedImage);
                      } catch (FileNotFoundException e) {
                          e.printStackTrace();
                      }
                      Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
                      int nh = (int) (yourSelectedImage.getHeight() * (512.0 / yourSelectedImage.getWidth()));
                      Bitmap scaled = Bitmap.createScaledBitmap(yourSelectedImage, 512, nh, true);
                      imageToUpload.setImageBitmap(scaled);
  
                  }
          }
      }
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/197149/ORIGINAL/NONE/724456777 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F197149/ORIGINAL/NONE/724456777} }} to activity {com.yitter.android/com.yitter.android.activity.YeetActivity}: java.lang.IllegalArgumentException: width and height must be &gt; 0
  
  
  at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
                                                                          at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
                                                                          at android.app.ActivityThread.-wrap16(ActivityThread.java)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                       Caused by: java.lang.IllegalArgumentException: width and height must be &gt; 0
                                                                          at android.graphics.Bitmap.createBitmap(Bitmap.java:829)
                                                                          at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
                                                                          at android.graphics.Bitmap.createBitmap(Bitmap.java:739)
                                                                          at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:615)
                                                                          at com.yitter.android.activity.YeetActivity$override.onActivityResult(YeetActivity.java:350)
                                                                          at com.yitter.android.activity.YeetActivity$override.access$dispatch(YeetActivity.java)
                                                                          at com.yitter.android.activity.YeetActivity.onActivityResult(YeetActivity.java:0)
                                                                          at android.app.Activity.dispatchActivityResult(Activity.java:6456)
                                                                          at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
                                                                          at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) 
                                                                          at android.app.ActivityThread.-wrap16(ActivityThread.java) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:148) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>
  
  <p> </p>
  
  <p>My first suspicion was that the error occurs where I'm scaling the camera image down, but it's not so obvious from my stack trace. When I remove the two lines of code responsible for rescaling the image, I get the following error:</p>
  
  <pre><code>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent {  }} to activity {com.yitter.android/com.yitter.android.activity.YeetActivity}: java.lang.NullPointerException: uri
                                                                        at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
                                                                        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
                                                                        at android.app.ActivityThread.-wrap16(ActivityThread.java)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                     Caused by: java.lang.NullPointerException: uri
                                                                        at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:60)
                                                                        at android.content.ContentResolver.openInputStream(ContentResolver.java:645)
                                                                        at com.yitter.android.activity.YeetActivity.onActivityResult(YeetActivity.java:366)
                                                                        at android.app.Activity.dispatchActivityResult(Activity.java:6456)
                                                                        at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
                                                                        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) 
                                                                        at android.app.ActivityThread.-wrap16(ActivityThread.java) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:148) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>
  
  <p>What could be going wrong?</p>