Hello, and can anyone tell me why this wont work?
in
Programming Questions
•
1 month ago
Hello all,
I have dabbled with various languages throughout the years, being able to cobble together bits and pieces to get them to work, but have never completely gotten to grips with OOP concepts and learned a language properly.
I have made the decision to to properly learn to think like a programmer using Processing. I have posted here before, but will now probably be asking questions quite regularly on this forum as I persist in learning this fun language.
Anyways...
I have learned about scoping, but cannot figure out why I am getting problems with the below code.
filenames[] returns null so I get a null pointer.
- import java.io.*;
- File folder = new File(sketchPath("") + "/images");
- String filterExtension = ".jpg";
- FilenameFilter jpgFilter = new FilenameFilter()
- {
- boolean accept(File dir, String name)
- {
- return name.toLowerCase().endsWith(".jpg");
- }
- };
- String[] filenames = folder.list(jpgFilter);
- void setup() {
- println(sketchPath("") + "/images");
- if (filenames == null)
- {
- println("No files found");
- }
- println(filenames.length + " " + filterExtension + " files in specified directory");
- for (int i = 0; i < filenames.length; i++)
- {
- println(filenames[i]);
- }
- }
- void draw() {
- }
If I remove the startup and draw loops ( entering static mode) it is fine. Surely the folder var is defined globally?
Cheers
- Roo
1