Program to get all files within a directory in Java
<p>I'm working on this program to get all the files in the directory.  For some reason I am getting a NullPointerException on Line 16.  I don't know why though since this is a template that seemed to work in class with our teacher.  Thanks.</p>

<pre><code>import java.util.*;
import java.io.*;

public class FindDirectories {
    public static void main(String[] args) { 
        if (args.length == 0) { 
            args = new String[] { ".." }; 
        }

        List&lt;String&gt; nextDir = new ArrayList&lt;String&gt;(); 
        nextDir.add(args[0]); // either the one file, or the directory
        try { 
            while(nextDir.size() &gt; 0) {     // size() is num of elements in List 
                File pathName = new File(nextDir.get(0)); // gets the element at the index of the List 
                String[] fileNames = pathName.list();  // lists all files in the directory
                for(int i = 0; i &lt; fileNames.length; i++) { 
                  File f = new File(pathName.getPath(), fileNames[i]); // getPath converts abstract path to path in String, 
                                                                    // constructor creates new File object with fileName name   
                  if (f.isDirectory()) { 
                     System.out.println(f.getCanonicalPath()); 
                     nextDir.add(f.getPath()); 
                  } 
                  else {
                      System.out.println(f);
                  }
               } 
               nextDir.remove(0); 
            } 
        } 
        catch(IOException e) { 
            e.printStackTrace();  
        }       
    } 
}
</code></pre>
