I modified my csv fila but now I am getting NullPointerException errror
My code is:
String infile = "data/data.csv";
Table table;
Bubble[] bubbles;
void setup() {
table = loadTable(infile,"header , csv" );
}
void draw() {
background(255);
// Display all bubbles
for (int i = 0; i<bubbles.length; i++) {
bubbles[i].display();
}
}
void loadData() {
// "header" indicates the file has header row. The size of the array
// is then determined by the number of rows in the table.
//table = loadTable(infile, "header , csv");
bubbles = new Bubble[table.getRowCount()];
for (int i = 0; i<table.getRowCount(); i++) {
// Iterate over all the rows in a table.
TableRow row = table.getRow(i);
// Access the fields via their column name (or index).
float x = row.getFloat("x");
float y = row.getFloat("id");
float d = row.getFloat("diameter");
String n = row.getString("name");
// Make a Bubble object out of the data from each row.
bubbles[i] = new Bubble(x, y, d, n);
}
}
void mousePressed() {
// When the mouse is pressed, create a new row and set the values for each column of that row.
TableRow row = table.addRow();
row.setFloat("x", mouseX);
row.setFloat("y", mouseY);
row.setFloat("diameter", random(40, 80));
row.setString("name", "Blah");
// If the table has more than 10 rows, delete the oldest row.
if (table.getRowCount()>10) {
table.removeRow(0);
}
// This writes the table back to the original CSV file
// and reloads the file so that what's drawn matches.
saveTable(table, "data/data.csv");
loadData();
}
// This simple Bubble class draws a circle to the window
// and displays a text label when the mouse hovers.
class Bubble {
float x, y;
float diameter;
String name;
boolean over = false;
// Create the Bubble
Bubble(float tempX, float tempY, float tempD, String s) {
x = tempX;
y = tempY;
diameter = tempD;
name = s;
}
// Checking if mouse is over the bubble
void rollover(float px, float py) {
float d = dist(px, py, x, y);
if (d<diameter/2) {
over = true;
} else {
over = false;
}
}
// Display the Bubble
void display() {
stroke(0);
strokeWeight(2);
noFill();
ellipse(x, y, diameter, diameter);
if (over) {
fill(0);
textAlign(CENTER);
text(name, x, y+diameter/2+20);
}
}
}