We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello all, I want to write a code to select a ".csv" file and graph the corresponding data. So far I've been able to do those separately but not together.
Table table;
String myFilePath;
TableRow row;
float Time;
float Manom;
float Temp;
float P1;
float GV1;
float P2;
float GV2;
float P3;
float GV3;
float P4;
float GV4;
float P5;
float GV5;
float P6;
float GV6;
float x;
int var;
Bubble[] bubbles;
void setup() {
size(1000, 800);
surface.setResizable(true);
selectInput("Select a file to process:", "fileSelected");
loadData();
}
void fileSelected(File selection) {
myFilePath = selection.getAbsolutePath();
table = loadTable(myFilePath, "header");
}
void draw(){
if(table == null){
background(0,0,155);
noLoop();
} else {
background(155,50,50);
for (int i = 0; i < bubbles.length; i++) {
bubbles[i].display();
}
}
}
void loadData(){
if (table != null){
background(70);
table = loadTable(myFilePath, "header");
bubbles = new Bubble[table.getRowCount()];
for (int i = 0; i < table.getRowCount(); i++){
row = table.getRow(i);
Time = row.getInt("Time (s)");
Manom = row.getFloat("1");
Temp = row.getFloat("2");
P1 = row.getFloat("3");
P2 = row.getFloat("4");
P3 = row.getFloat("5");
P4 = row.getFloat("6");
P5 = row.getFloat("7");
P6 = row.getFloat("8");
GV1 = row.getFloat("9");
GV2 = row.getFloat("10");
GV3 = row.getFloat("11");
GV4 = row.getFloat("12");
GV5 = row.getFloat("13");
GV6 = row.getFloat("14");
x = map(Time, 0, table.getRowCount(), 100, 900);
}
}
}
Main code with class Bubble
class Bubble {
float x,y;
float diameter;
Bubble(float x_, float y_, float diameter_) {
x = x_;
y = y_;
diameter = diameter_;
}
void display() {
stroke(0);
strokeWeight(2);
noFill();
ellipse(x,y,diameter,diameter);
}
}
running this code gives me this error
Answers
Please post your entire code as text and not as an image
@Chrisir sorry, first time posting. Should look better now.
Call loadData only from fileselected and not from setup () --- setup doesn't wait!!!
Don't use noLoop
Or use loadData from draw
Just tried putting loadData in several different spots including draw and fileselected and got the same error.
I cant read your screen shot. :-?? Knowing the error is half of the solution... Regarding inputSelect: It is better if you copy and paste your error here in the forum. You can call load data in setup but then you have to make sure you access the data only after the data has been loaded. Check the concept below.
Kf
please show the first 5 lines of the table / csv
here is my version
Does my sketch work for you?
I got a NullPointerException error and it printed the header row
@kfrajer this is the error I was getting with my first code.
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at processing.core.PApplet.selectCallback(PApplet.java:6543) at processing.core.PApplet.access$1(PApplet.java:6536) at processing.core.PApplet$3.run(PApplet.java:6447) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: java.lang.IllegalArgumentException: No extension specified for this Table at processing.data.Table.parse(Table.java:369) at processing.data.Table.(Table.java:154) at processing.core.PApplet.loadTable(PApplet.java:6071) at processing.fileSelected(processing.java:49) ... 21 more
So does my sketch work ?
Try to fix my sketch please for your needs
@Chrisir your fixes took it from the error above to a NullPointerException and highlighted bubbles[i].display() under draw. both ways work until after I choose a file.
Does my sketch print the first line of the file?
@Chrisir yes it does
Try another newly made file please
Strange
Oh, wait I think you forgot to fill bubbles
You need after line 93
bubbles[i] = new Bubble(......
Not sure what 81 to 92 do
You overwrite the values all the time
Shouldn't all those variables be part of the class?
@Chrisir it works! I just need to do some tweaking. Rows 81-92 call all the values in a corresponding column.
In the error I see:
I will suggest to skip the selectinput() function and load the table manually by specifying the extension and see if that solve this part of the program. Or you can use the option parameters while loading tables: https://processing.org/reference/loadTable_.html
Notice also that in the data sample you provided, you have 15 columns in your header but you have this: "Time (s)" and this is not good as this will be counted as two field. Change it to either "Time(s)" or just "Time".
Kf
The two posts overlapped I guess
It's solved, it was the missing filling of bubbles
We looked in the wrong place