Csv does not exist or could not be read NullPointerException

I am having possibly the same problem. I have a .csv file with coordinates information that I want to draw. It worked fine this morning but can’t possibly get it to work now with error:
“data/posit18.csv does not exist or could not be read
NullPointerException”
I am attaching (in next comment) code and .csv file.
Thanks a lot.

Table table;
//PImage img1;

ArrayList<Float> x = new ArrayList<Float>();
ArrayList<Float> th1 = new ArrayList<Float>();
ArrayList<Float> th2 = new ArrayList<Float>();
ArrayList<Integer> F = new ArrayList<Integer>();
float X=0;
 int i=0;
 float pole1X, pole1Y,pole2X,pole2Y;
 float l1=200; 
 float l2=100;
float RecWidth=450;
float RecHeight=50;
float Offset=100;


void setup() {
  
  size(1300,600);
  frameRate(100);
  background(0);
  
  //img1 = loadImage("train.jpg");
  
  table = loadTable("data/posit1.csv", "header");
  println(table.getRowCount() + " total rows in table"); 
 
  for (TableRow row : table.rows()) {
 
    x.add(row.getFloat("x"));
    th1.add(row.getFloat("th1"));
    th2.add(row.getFloat("th2"));
    F.add(row.getInt("F"));
 
    
     //println("x= "+x+" th1= "+th1+" th2= "+th2);
  }
}

void draw(){
  if(i>x.size()-2){
   noLoop();
  }
  background(255);
  //println("x= "+x.get(i)+" th1= "+th1.get(i)+" th2= "+th2.get(i));
  stroke(255,0,0);
  line(0,0,0,height);
  line(width,0,width,height);
  
  
  
  stroke(0);
  fill(0);
  strokeWeight(4);
  line(0,height-50, width, height-50);
  rectMode(CENTER);
  X=map(x.get(i), -2.4, 2.4, RecWidth/2, width-RecWidth/2);
  println("x = "+x.get(i)+" - pxX = "+X+"\n");

  rect(X, height-75, RecWidth ,RecHeight);
  strokeWeight(10);
  stroke(139,69,19);
  pole1X=(X-Offset)+l1*(sin(th1.get(i)));
  pole1Y=(height-75-RecHeight/2-l1)-l1*cos(th1.get(i));
  line(X-Offset,height-75-RecHeight/2,pole1X,pole1Y);
  
  pole2X=(X+Offset)+l2*(sin(th2.get(i)));
  pole2Y=(height-75-RecHeight/2-l2)-l2*cos(th2.get(i));
  line(X+Offset,height-75-RecHeight/2,pole2X,pole2Y);
  stroke(0,255,0);
  fill(0,255,0);
  if(F.get(i)>8){
  triangle(X-RecWidth/2,height-75,X-RecWidth/2-100,height-125,X-RecWidth/2-100,height-25);
  }
  else if (F.get(i)<-8){
  triangle(X+RecWidth/2,height-75,X+RecWidth/2+100,height-125,X+RecWidth/2+100,height-25);
  }
  
  
  
  i++;
}

please open your own TOPIC

but read this one first about processing folder / file structure

also if you read that already you should know that
info about path and filename is essential to this question

but code and data NOT,
only the

Table table;
String infile = "data/posit18.csv";
//..
table = loadTable(infile, "header, csv");

but as you show this already
even you get your project / file path correct

  • – that is not a csv file!! should be like
x,th1,th2,F
-0.00099,0.018381,0.009091,-10
-0.00099,0.018419,0.009189,10

processing loadTable can only use true .csv .tsv


and i have no idea why you try transfer from table to array
( only needed in rare occasions )

1 Like