Created
January 31, 2015 21:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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