Hello – I’m working on a project that uses CSV data to drive the graphics; I created a Show Control class that reads all of the csv files in a folder, and then grabs the next available row from the current file to provide values for the graphics. However, I’m running into a strange error where every /other/ row returns NaN for the cell values, and then the other rows return valid values.
The class is here:
class ShowControl {
ArrayList<Table> mShowList = new ArrayList<Table>(10);
int mShowIndex = 0;
int mCurrentShowLocation = 0;
Table mCurrentShow = null;
ShowControl() {
String[] fileList;
File file = new File(dataPath(""));
if (file.isDirectory()) {
fileList = file.list();
} else {
fileList = null;
}
printArray(fileList);
if(fileList != null) {
for(String filename : fileList) {
Table t = loadTable(filename, "header");
mShowList.add(t);
}
}
if(mShowList.size() > 0) {
mCurrentShow = mShowList.get(mShowIndex);
}
}
void update() {
if(mCurrentShowLocation < mCurrentShow.getRowCount() - 1) {
mCurrentShowLocation++;
}
else {
mShowIndex++;
mShowIndex = mShowIndex % mShowList.size();
println("Current Show Index: " + mShowIndex);
mCurrentShow = mShowList.get(mShowIndex);
mCurrentShowLocation = 0;
}
}
void restartShow() {
mCurrentShowLocation = 0;
}
float getValue(String fieldName) {
println("Show Location: " + mCurrentShowLocation);
println("Field Name: " + fieldName);
println(mCurrentShow.getFloat(mCurrentShowLocation, fieldName));
return mCurrentShow.getFloat(mCurrentShowLocation, fieldName);
}
}
and the code that I’m calling in draw() is this:
mShowControl.update();
float pos_x = mShowControl.getValue("Gallery X");
float pos_y = mShowControl.getValue("Gallery Y");
float pos_z = mShowControl.getValue("Gallery Z");
which prints data like this:
Show Location: 155
Field Name: Gallery X
69.0
Show Location: 155
Field Name: Gallery Y
69.0
Show Location: 155
Field Name: Gallery Z
2.37
Show Location: 156
Field Name: Gallery X
NaN
Show Location: 156
Field Name: Gallery Y
NaN
Show Location: 156
Field Name: Gallery Z
NaN
The csv file looks fine in every way, so I’m very confused how even rows provide incorrect data but odd rows work fine!
Does anyone have any thoughts?