Skip to content

Instantly share code, notes, and snippets.

@kineticz
Created January 31, 2015 21:34
Show Gist options
  • Select an option

  • Save kineticz/32d6e3158cbb92bf8dd6 to your computer and use it in GitHub Desktop.

Select an option

Save kineticz/32d6e3158cbb92bf8dd6 to your computer and use it in GitHub Desktop.
Why do I get a nul pointer exception? From what I see from the debugger, `File d` is not null.
package je3.io;
import java.io.File;
import java.util.List;
/**
* Created by IDEA on 31/01/15.
*/
public class WalkDir {
private List<File> recursiveList;
public void walkDir(String pathname) {
File d = new File(pathname);
recursiveList.add(d);
if(d.isDirectory()) {
for(String f : d.list()) {
walkDir(f);
}
}
}
public List<File> getRecursiveList() {
return recursiveList;
}
public static void main(String[] args) {
WalkDir dirWalker = new WalkDir();
dirWalker.walkDir("/tmp/test");
for(File f : dirWalker.getRecursiveList()) {
System.out.println(f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment