We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey I was hoping to use this jpg file listing tutorial in my program, but it doesn't seem to work- does anyone know how to fix it? http://wiki.processing.org/w/Listing_files
Rigth now, it's giving a NullPointerException here-
println(filenames.length + " jpg files in specified directory");
which I have figured means that filenames is probably not well declared. Or can't be read or something. I suspect it's because folder.list() is not really a thing- the reference seems to indicate it's only for fonts. Is it because the tutorial is old? Is there a way to update it?
Andddd once that's been figured out, is there a way to make it read any folder and not just the data one from the sketch (which I assume is what it does)?
Thanks so much for any tips on how to make this work!!!
(In case you're interested, I'm going to use it to display a bunch of images without having to write the name of each file in the code)
Answers
You first need to specify the path to the directory. If it is empty you get NullPointerException. To list all the folders you need a new filter that has isDirectory() inside. Then list() the folder path. Also note that the path has "/" instead of "\". The second one is for ignoring characters in a string. Here is the example
Oh dear. Just adding something in the directory path. That was easy. Thanks ;;) It's kinda silly because I thought of doing it but then I got some weird errors because I didn't know about backslashes. The more you know...