title: Android - Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
body: <p>I am making an app to click photos and then upload the same on Firebase storage but I am getting this <code>nullpointer</code> exception in my code. </p>
  
  <p>I have tried bitmap image too but it didn't help as I am still getting the same error. 
  This is my code below of the <code>onActivityResult</code> method:</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if(requestCode==CAMERA_REQUEST_CODE&amp;&amp; resultCode==RESULT_OK){
  
              Uri uri=data.getData();
              StorageReference filepath =mStorage.child("Photos").child(uri.getLastPathSegment());
  
             filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                  @Override
                  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                   Uri downloadUri = taskSnapshot.getUploadSessionUri();
  
  
                      Toast.makeText(MainActivity.this,"upload finished",Toast.LENGTH_LONG).show();
                  }
              }).addOnFailureListener(new OnFailureListener() {
                  @Override
                  public void onFailure(@NonNull Exception e) {
                      Toast.makeText(MainActivity.this, "Sending failed", Toast.LENGTH_SHORT).show();
  
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>The error that I am getting:</p>
  
  <blockquote>
    <p>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference</p>
  </blockquote>