We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hey my fellow coders i keep getting a java.lang.NullPointerException error message on my processing sketch. Not Sure what i did wrong could anyone possibly help me. Its for a project i'm in desperate need of help. Basically what i'm trying to do is map out sets of data measuring atmospheric carbon dioxide levels. I'll attach the data as a csv file along with code. If anyone could help i would be truly thankful :)
heres the code:
// How to read CSV files using the Table class
void setup() {
size(500, 400, P3D);
background(0);
stroke(255);
Table data = loadTable("co2.csv", "header,csv");
//translate(width/2, height/2);
//rotateX(PI/2);
for (TableRow row: data.rows()) {
//average amounts of co2 emission per year
float average = row.getFloat("average");
average = int(average);
//interpolated points
float interpolated = row.getFloat("interpolated");
interpolated= int(interpolated);
//trend of co2 emissions
float trend = row.getFloat("trend");
trend= int(trend);
//dates recorded
float date = row.getFloat("date");
date= (date);
//days
float days = row.getFloat("days");
days= int(days);
//float date = row.getFloat("date");
//if (date > 2000) {
//float = average // <--- needs work
//point(x, y);
//x++;
//visual part
//average between 2000-2013
float x1= map(average, 369.25, 398.4, 0, width);//first value being the max second min
stroke(0, 255, 0);//green line represents years
point(x1, 10);
//line for trend of emissions between 2000-2013
float r = 0;//radius
float x2 = map(trend, 369.06, 396.83, 0, width);
stroke(0, 0, 255);//blue dots represents trends between 2000-2013
point(x1, x2);
// interpolated points in graph
float interpolated1 = map(interpolated, 369.25, 399.767, 0, width);
stroke(234, 31, 129);//red dots represent interpolated plots in graph
point(x1, interpolated1);
//days it took to record data each year
float days1 = map(days, 14, 31, 0, width);
stroke(255, 247, 8);//purple dots represent days
point(x1, days1);
}
}
Answers
W/o "co2.csv" we can't run your code! :-w
Also when posting, highlight it and then hit CTRL+K to format it! :ar!
Can help to point out where the error happens, since, as pointed out, we cannot run your code.
See also Why do I get a NullPointerException?