title: Android studio Image uploading error Firebase
body: <p>Hello I got an error while uploading image to Firebase. I run this same code in activity when I set up profile and there it runs perfect but when I got this in activity where you can change profile picture there come an error.</p>
  
  <p>Error message</p>
  
  <pre><code>Exception java.lang.RuntimeException: Failure delivering result 
  
  ResultInfo{who=null, request=2, result=-1, data=Intent { dat=file:///storage/emulated/0/DCIM/Facebook/FB_IMG_1476211508746.jpg typ=image/jpeg }} to activity {com.samo.facedatefb/com.samo.facedatefb.Settings}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
  android.app.ActivityThread.deliverResults (ActivityThread.java:3741)
  android.app.ActivityThread.handleSendResult (ActivityThread.java:3784)
  android.app.ActivityThread.access$1300 (ActivityThread.java:169)
  android.app.ActivityThread$H.handleMessage (ActivityThread.java:1472)
  android.os.Handler.dispatchMessage (Handler.java:11
  android.os.Looper.loop (Looper.java:194)
  android.app.ActivityThread.main (ActivityThread.java:5546)
  java.lang.reflect.Method.invoke (Method.java)
  java.lang.reflect.Method.invoke (Method.java:372)
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:967)
  com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
  arrow_drop_down
  Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
  com.samo.facedatefb.Settings.onActivityResult (Settings.java:232)
  android.app.Activity.dispatchActivityResult (Activity.java:6177)
  android.app.ActivityThread.deliverResults (ActivityThread.java:3737)
  android.app.ActivityThread.handleSendResult (ActivityThread.java:3784)
  android.app.ActivityThread.access$1300 (ActivityThread.java:169)
  android.app.ActivityThread$H.handleMessage (ActivityThread.java:1472)
  android.os.Handler.dispatchMessage (Handler.java:111)
  android.os.Looper.loop (Looper.java:194)
  android.app.ActivityThread.main (ActivityThread.java:5546)
  java.lang.reflect.Method.invoke (Method.java)
  java.lang.reflect.Method.invoke (Method.java:372)
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:967)
  com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
  </code></pre>
  
  <p>And here is code</p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (requestCode == GALLERY_INTENT &amp;&amp; resultCode == RESULT_OK) {
          mProgressDialog.setMessage("Uploading...");
          mProgressDialog.show();
  
          StorageReference imageRef = mStorage.child(myEmail);
          StorageReference imageImagesRef = mStorage.child("photos/" + myEmail);
  
          imageRef.getName().equals(imageImagesRef.getName());    // true
          imageRef.getPath().equals(imageImagesRef.getPath());    // false
  
  
          Uri uri = data.getData();
          imageView.setImageURI(uri);
  
          imageView.setDrawingCacheEnabled(true);
          imageView.buildDrawingCache();
          Bitmap bitmap = imageView.getDrawingCache();
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
          byte[] data2 = baos.toByteArray();
  
          UploadTask uploadTask = imageImagesRef.putBytes(data2);
          uploadTask.addOnFailureListener(new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception exception) {
                  // Handle unsuccessful uploads
                  Toast.makeText(getApplicationContext(), "Sorry, your image wasn't set, please try again",
                          Toast.LENGTH_LONG).show();
              }
          }).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
              @Override
              public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                  // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
                  mProgressDialog.dismiss();
                  Toast.makeText(getApplicationContext(), "Upload done",
                          Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent(getApplicationContext(), MapsActivity.class);
                  startActivity(intent);
              }
          });
      }
  } 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>} else if (arrayList.get(position).equals("Change profile photo")) {
         Intent intent = new Intent(Intent.ACTION_PICK);
         intent.setType("image/*");
         startActivityForResult(intent, GALLERY_INTENT);
  }
  </code></pre>