• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFileChooser selecting multiple files from different directories

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That just means that the "filesToMerge" variable is null. You're getting distracted by the JFileChooser, which is working perfectly well. And so is your code, up to that point.
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:That just means that the "filesToMerge" variable is null. You're getting distracted by the JFileChooser, which is working perfectly well. And so is your code, up to that point.



Great, thanks! I thought the sourceFile variable was null.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic