title: Not able to list the available files present in the file path in android
body: <p>I am not able to get the list of files from this code. It throws null pointer on files. Please help to find the issue. I can see the target path in the toast as well. what am I missing here.</p>
  
  <p>Thanks in Advance.</p>
  
  <p>Stacktrace :</p>
  
  <pre><code>01-21 10:30:12.301: D/Debug(18384): /storage/emulated/0/test
  01-21 10:30:12.301: D/Debug(18384): Already present
  01-21 10:30:12.301: D/Debug(18384): No list/storage/emulated/0/test
  </code></pre>
  
  <p>Code used : </p>
  
  <pre><code>    String ExternalStorageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath();
  
      String targetPath = ExternalStorageDirectoryPath + "/test";
       Log.d("Debug",targetPath);   
      //Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
      try{
      File targetDirector = new File(targetPath);
      if(targetPath!=null)
      {
          if(!targetDirector.exists())
              {
                  targetDirector.mkdir();
                  Log.d("DIRECtory","Created");
              }
          else
              Log.d("Debug", "Already present");
      }
      // Added these lines to debug 
      if(targetDirector!=null)
          Log.d("Size","Size = "+targetDirector.listFiles().length); //App crashes here inside if
      else
          Log.d("TargetDir", "TargetDir is null");
      File[] files = targetDirector.listFiles();
      if(files!=null)
          {
              for (File file : files){
                  myImageAdapter.add(file.getAbsolutePath());
              }
          }
      else
      {
          Log.d("Debug","No list"+targetDirector);
      }
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }
  </code></pre>