Thanks for the replies. I changed the readData function like you said but I got the error saying cannot find Class named lecturer, so I moved the Lecturer class to the top of my file. I then realised the example I was following was a .tsv file and mine was a csv making this line of my code wrong (I think):
String pieces[] = split(line, TAB );
So I now changed my excel file to lecturer.txt tsv file and my code now looks like this:
class Lecturer {
String department;
String name;
float x;
float y;
public Lecturer(String department, String name, float x, float y) {
this.department = department;
this.name = name;
this.x = x;
this.y = y;
}
}
static final int DEPARTMENT = 1;
static final int X = 2;
static final int Y = 3;
static final int NAME = 4;
int totalCount; // total number of lecturers
Lecturer[] lecturers;
int lecturerCount;
// min/max boundary of all points
float minX, maxX;
float minY, maxY;
public void setup() {
readData();
}
void readData() {
String[] lines = loadStrings("lecturer.txt");
// Skip the header line
totalCount = lines.length - 1;
lecturers = new Lecturer[totalCount];
for ( int i = 1; i < lines.length; i++){
lecturers[lecturerCount] = parseLecturer(lines[i]);
lecturerCount++;
}
}
Lecturer parseLecturer(String line) {
String pieces[] = split(line, TAB );
String department = pieces[DEPARTMENT];
String name = pieces[NAME];
float x = float(pieces[X]);
float y = float(pieces[Y]);
return new Lecturer(department, name, x, y);
}
Suprisingly
it still doesnt work and is giving me the error
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 4
at test.parseLecturer(test.java:65)
at test.readData(test.java:56)
at test.setup(test.java:47)
at processing.core.PApplet.handleDraw(PApplet.java:1402)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:619)
All Im trying to do is get the program to load in the information and later im going to work on mapping it to the screen. Can anyone please suggest a simplier way of doing this??