I am writing a program that uses File I / O to go through a directory specified by the user and then adds directories to the general list of links. The program I wrote works fine on Ubuntu, but does not work when I try to use it on Windows. This is a pretty long program, but this is the part that I think has problems:
private Node<Item> currentNode = new Node<Item>(); public void traverse(File fileObject) { File allFiles[] = fileObject.listFiles(); for(File aFile: allFiles){ System.out.println(aFile.getName()); recursiveTraversal(aFile); } } public void recursiveTraversal(File fileObject){ Node<Item> newNode = new Node<Item>(); currentNode.addChild(newNode); currentNode = newNode; if (fileObject.isDirectory()){ newNode.setData(new Item()); File allFiles[] = fileObject.listFiles(); for(File aFile : allFiles){ recursiveTraversal(aFile); } }else if (fileObject.isFile()){ newNode.setData(new Item()); } currentNode = newNode.getParent(); }
When I use it on Linux, I can give it something like /home/matt/Documents , and it works, but when I try to use Windows with G:\\Users\\Matt\\Documents , this leads to errors . The print statement I selected actually prints the files in the folder, but something with the rest of the program gets confused:
java.lang.NullPointerException at FileTraverse.recursiveTraversal(FileTraverse.java:48) at FileTraverse.traverse(FileTraverse.java:34) at DirectoryMain$ClickAction.actionPerformed(DirectoryMain.java:103) ...
After that, there are many errors associated with the Swing GUI, from which this program ends, but I do not think that this is related to anything.
EDIT: Added line numbers that match the trace.
source share