title: Null Pointer exception while taking pictures on Android Api >=23
body: <p>I have searched a lot but nothing helped me so i am posting my own question.</p>
  
  <p>My problem is while taking pictures in Android Marshmallow and above, it is giving me error</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: uri</p>
  </blockquote>
  
  <p>Note: It is working fine below Api Level 22</p>
  
  <p>My code is</p>
  
  <pre><code> @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
  
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == this.RESULT_CANCELED) {
          return;
      }
  
      if (requestCode == GALLERY) {
          filePath = data.getData();
  Uri uri = data.getData();
                  // imageView.setImageURI(uri);
                  try {
  
                      Log.d("waqarr",""+ Arrays.toString(convert(getPath(filePath))));
                      File f = new File(getPath(filePath));
                      file_name = f.getName();
  
                      Uri selectedImage = data.getData();
                      //ShowImageDialog();
                      if(filePath!= null)
                      {
                          multipart();
                      }
                      } catch (IOException e) {
                      e.printStackTrace();
                  }
      }
      } else if (requestCode == CAMERA) {
          Bitmap photo = (Bitmap) data.getExtras().get("data");
  
         // filePath = getImageUri(getApplicationContext(), photo);
          filePath = data.getData();
          try {
  
              Log.d("waqarr", "  " + Arrays.toString(convert(getPath(filePath))));
              File f = new File(getPath(filePath));
              file_name = f.getName();
  
              multipart();
  
          } catch (IOException e) {
              e.printStackTrace();
          }
      }} public String getPath(Uri uri)
  {
      String[] filePathColumn = {MediaStore.Images.Media.DATA};
      Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
      cursor.moveToFirst();
      String document_id = cursor.getString(0);
      document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
      cursor.close();
      cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
              null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
      cursor.moveToFirst();
      String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
      cursor.close();
      return path;
  }
  </code></pre>
  
  <p>Any help will be appreciated.</p>