title: Android: Show files in the storage with certain extentions in a listview
body: <p>I'm creating an activity that shows files in the device (including external storage) with '.mp4' extension in a ListView. </p>
  
  <p>Here's my <strong>Activity file</strong></p>
  
  <pre><code>public class FindVideoActivity extends AppCompatActivity {
  
  private List&lt;String&gt; fileNames;
  private ListView lv;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_find_video);
  
      fileNames = new ArrayList&lt;&gt;();
      lv = (ListView) findViewById(R.id.find_video_list);
  
      updateFileList();
  }
  
  public void updateFileList() {
      String path;
  
      String extension = Environment.getExternalStorageState();
      if(extension.equals(Environment.MEDIA_MOUNTED)) {
          path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/videostreaming/";
      } else {
          path = Environment.MEDIA_UNMOUNTED;
      }
  
      File file = new File(path);
  
      ArrayAdapter&lt;String&gt; fileList = new ArrayAdapter&lt;&gt;(this, R.layout.file_list_item, fileNames);
  
      VideoFinder finder = new VideoFinder();
      File[] files = file.listFiles(finder);
  
      for(File f: files) {
          fileNames.add(f.getName());
      }
  
      lv.setAdapter(fileList);
    }
   }
  </code></pre>
  
  <p>In order to filter out the '.mp4' files, I created another class and named it VideoFinder.java. This class implements <code>java.io.FilenameFilter</code>. Here's the code.</p>
  
  <pre><code>public class VideoFinder implements FilenameFilter {
  
  // overriding the method from the FilenameFilter interface.
  @Override
  public boolean accept(File dir, String filename) {
      if(filename.endsWith(".mp4")) {
          return true;
      }
      return false;
     }
    }
  
  When I run the code above, it returns `NullPointerException` like the following.
  
  Caused by: java.lang.NullPointerException
                                                       at com.marshall.videostreaming.FindVideoActivity.updateFileList(FindVideoActivity.java:46)
                                                       at com.marshall.videostreaming.FindVideoActivity.onCreate(FindVideoActivity.java:26) 
  </code></pre>
  
  <p>So it says that the <code>for</code> loop in the <code>updateFileList()</code> method is catching the exception. I still cannot catch what I am missing in this code. Can anyone help?</p>