title: get mp3 files from path
body: <p>I'm trying to get mp3 files from a folder path of my system to list it in my listView, but unfortunately there's always the same error. (java.lang.NullPointerException: Attempt to get length of null array)</p>
  
  <pre><code>class Mp3Filter implements FilenameFilter{
  public boolean accept(File dir, String name){
      return (name.endsWith(".mp3"));
  }
  }
  
  private static final String SD_PATH = new String(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).toString());
  
  public void searchForSongs() {
  
      ListView listView;
      listView = (ListView) findViewById(R.id.listView);
  
      File f = new File(SD_PATH);
  
     try {
  
            if (f.listFiles(new Mp3Filter()).length &gt; 0){
             for (File file : f.listFiles(new Mp3Filter())){
                    list.add(file.getName());
                }
         }
  
      }
  
      catch(Exception e) {
          textView2.setText(""+e);
          return;
      }
  
      final ArrayAdapter songList = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
      listView.setAdapter(songList);
  }
  </code></pre>