title: cursor.getString(dataColumnIndex) Give Null Pointer exception
body: <p>I am trying to load all the images present in an Android devices using the Media Store.</p>
  
  <p>This is what I am doing</p>
  
  <pre><code>public void getImages(Context context) {
      File Image_File;
      final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
      String orderBy = MediaStore.Images.Media.DATE_MODIFIED ;
      Cursor cursor = context.getContentResolver().query(
          MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
          null, orderBy);
  
      if (cursor != null){
          cursor.moveToFirst();
          final int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
          while (cursor.moveToNext()) {
              Image_File = new File(cursor.getString(dataColumnIndex));
          }
      }
    }
  }
  </code></pre>
  
  <p>But the below line gives me an error </p>
  
  <pre><code>Image_File = new File(cursor.getString(dataColumnIndex));
  </code></pre>
  
  <p>This is the error which is appearing</p>
  
  <blockquote>
    <p>Caused by java.lang.NullPointerException
        Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference</p>
  </blockquote>
  
  <p>And this is the full Stack Trace</p>
  
  <blockquote>
    <p>Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
            at java.io.File.fixSlashes(File.java:185)
            at java.io.File.(File.java:134)
            at PackageName.getImages(ClassName.java:87)
            at PackageName.ClassName$load.doInBackground(ClassName.java:52)
            at PackageName.ClassName$load.doInBackground(ClassName.java:39)
            at android.os.AsyncTask$2.call(AsyncTask.java:292)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)</p>
  </blockquote>
  
  <p><strong>I am aware that there are other SO posts which talk about this topic such as <a href="https://stackoverflow.com/questions/39177616/cursor-getstring-null-pointer-exception-on-version-6-0">this</a> but then I feel they are nowhere related to my case.</strong></p>
  
  <p>This crash happens in Android versions from 5.0 to 7.0(My app's minimum Android version is 5.0).</p>
  
  <p>Any Help would be grateful as I am not able to retrace the issue on my Phone.</p>