nesting two selectInput() functions
in
Programming Questions
•
9 months ago
Hello all, hopefully this should be an easy one: I'd like to use the above function to select two different text files containing CSV data and then perform a mathematical operation on the data. Currently its throwing an error and I don't understand why. Have I structured this correctly?
The output window produces the following (note that I have prefaced each row of correct output with "$$$$" to highlight where the code has done thigns correctly):
- /*
- This code selects two files and performs a mathematical operation on the signal data in each row.
- */
- PrintWriter output;
- String folderPath; // folder path where logfiles will be saved
- String blankFilePath;
- String testFilePath;
- String blankFileName;
- String[] blankLines;
- String testFileName;
- String testFileFolderPath;
- String outputFile;
- String[] testLines;
- long index = 0;
- String[] blankData;
- // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- void setup() {
- selectInput("Select a blank file:", "blankSelected");
- }
- // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- void blankSelected(File selection) {
- if (selection == null) {
- println("Window was closed or the user hit cancel.");
- exit();
- }
- else {
- blankFilePath = selection.getAbsolutePath();
- blankFileName = selection.getName();
- println("blank file selected: " + blankFilePath);
- blankLines = loadStrings(selection);
- println(blankLines[0]);
- selectInput("Select a file to subtract:", "fileSelected");
- }
- output = createWriter(outputFile);
- for(String i : testLines) { // this is the main loop of the sketch - contains just test code for now
- blankData = split(i, ',');
- println(blankData[0]);
- println(index);
- index++;
- }
- exit();
- }
- // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
- void fileSelected(File selection) {
- if (selection == null) {
- println("Window was closed or the user hit cancel.");
- exit();
- }
- else {
- testFilePath = selection.getAbsolutePath();
- testFileFolderPath = selection.getParent();
- testFileName = selection.getName();
- String[] tFN = split(testFileName, '-');
- println("test file selected: " + testFilePath);
- outputFile = testFileFolderPath + "\\" + "LCMS mathematical operator output - " + tFN[1]; // text file to save output to
- println("output file: " + outputFile);
- testLines = loadStrings(selection);
- println(testLines[0]);
- }
- }
$$$$ blank file selected: C:\Google Drive\Chris Pook AUT\research\lipids LC-MS\2ul injections 12-12-13\ultimate txt writer\LCMS ultimate .txt writer output - 2ul blank crop.txt$$$$ 590.0,500.0,0java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at processing.core.PApplet.selectCallback(PApplet.java:6049)at processing.core.PApplet.access$000(PApplet.java:153)at processing.core.PApplet$5.run(PApplet.java:5975)at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)at java.awt.EventQueue.access$000(EventQueue.java:84)at java.awt.EventQueue$1.run(EventQueue.java:607)at java.awt.EventQueue$1.run(EventQueue.java:605)at java.security.AccessController.doPrivileged(Native Method)at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)Caused by: java.lang.NullPointerExceptionat java.io.File.<init>(File.java:222)at processing.core.PApplet.saveFile(PApplet.java:7024)at processing.core.PApplet.createWriter(PApplet.java:6168)at LCMS_mathematical_operator.blankSelected(LCMS_mathematical_operator.java:61)... 21 more$$$$ test file selected: C:\Google Drive\Chris Pook AUT\research\lipids LC-MS\2ul injections 12-12-13\ultimate txt writer\LCMS ultimate .txt writer output - 2ul 500mg.l tristearin crop.txt$$$$ output file: C:\Google Drive\Chris Pook AUT\research\lipids LC-MS\2ul injections 12-12-13\ultimate txt writer\LCMS mathematical operator output - 2ul 500mg.l tristearin crop.txtjava.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at processing.core.PApplet.selectCallback(PApplet.java:6049)at processing.core.PApplet.access$000(PApplet.java:153)at processing.core.PApplet$5.run(PApplet.java:5975)at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:646)at java.awt.EventQueue.access$000(EventQueue.java:84)at java.awt.EventQueue$1.run(EventQueue.java:607)at java.awt.EventQueue$1.run(EventQueue.java:605)at java.security.AccessController.doPrivileged(Native Method)at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)Caused by: java.lang.OutOfMemoryError: Java heap spaceat java.util.Arrays.copyOfRange(Arrays.java:3209)at java.lang.String.<init>(String.java:215)at java.io.BufferedReader.readLine(BufferedReader.java:331)at java.io.BufferedReader.readLine(BufferedReader.java:362)at processing.core.PApplet.loadStrings(PApplet.java:6646)at processing.core.PApplet.loadStrings(PApplet.java:6633)at processing.core.PApplet.loadStrings(PApplet.java:6567)at LCMS_mathematical_operator.fileSelected(LCMS_mathematical_operator.java:92)... 21 more
Many thanks,
NC
1