JFileChooser selecting multiple files from different directories
Joined: Sep 29, 2010
Hello Java Ranchers,
I'm trying to use a JFileChooser to select multiple files, either from the same directory or multiple directories. I have a fundamental misunderstanding of how to do this.
To select multiple files from the same directory, all I need to do is enable MultiSelection, which I've done. That works fine.
To select multiple files from different directories, I'm thinking I need to choose the files individually, then add them to an array of files, then pass that array to my other classes. This is where I'm running into problems, I think it has something to do with the File returned by the .getSelectedFiles method of the JFileChooser. I don't know what File is, the javadoc says it's "An abstract representation of file and directory pathnames." I'm not sure what to do with that.
This is what I tried first:
This gives me a run-time Null pointer exception, pointing to line 13. I can print out the pathname of the file, so it seems like there is a file there, but when I try to add that file to the array, it gives me the null pointer exception. I tried creating a new File from the File, but that didn't work either. So now I'm stuck.
Does anyone know how to make this work, or am I entirely on the wrong track for selecting multiple files from different directories?