We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have setup the callback function and it opens the File open dialog and I can choose the file but I don't understand how to get access to the filename. I have tried using a global variable that I set in the callback function but when I try to open a file I get a long list of java exceptions, the first couple of lines say
null does not exist or could not be read
An error occured during execution of the eventhandler:CLASS: EchoTapperPatchLibrarian METHOD: LoadButton_click1 Caused by java.lang.NullPointerException . etc. .
The section of the code where the selectInput() is called is
BufferedReader reader;
String line;
// Open the file
selectInput("Select a file to process:", "fileSelected");
println(filename);
reader = createReader(filename);
...
The program actually opens the file but I'm concerned by the exceptions!
The callback function is
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
}
else {
println("User selected " + selection.getAbsolutePath());
filename = selection.getAbsolutePath(); // filename is a global String variable
}
}
Does anyone know how to use selectInput() and selectOutput() properly?
Thanks for any help :-)
Phil.
Answers
After further investigation, I found that if you put the file processing code in the callback function, it works ok that way.
That is because the code handling the file chooser window runs in a separate thread, so after calling
selectInput()
it will not wait for this to finish but instantly go to the next statement. In other words at the time you work withfilename
there it is not yet set.Thanks fjen. That's what I finally figured out! I'm not as quick a study as I was in my youth ;-)
i have the same problem... how did you solve it?
Hi, sorry haven't been on here for a while. Try this ( Hopefully you can tease out the relevant parts for your application. )
so what should I do @fjen? I need process continue after file selection , how to push sketch to wait until file selection completed
One way to do things:
I hope this helps,
Kf