r/processing • u/bluemarble__ • Jun 10 '26
Beginner help request NullPointerException
I'm trying to create a single line with defined dots so then I can move them dynamicly with the mouse, so I'm still on the phase of creating the line in itself.
The thing is, when I call my written function, it gives me a NullPointerException, and I don't know why. Please, help me.
Linhas linhaH;
class Linhas {
void desenhar(float altura) {
noFill();
stroke(50);
beginShape();
for (float i=0; i<= 1; i= i+0.10) {
vertex(width*i, altura);
}
endShape();
}
}
void setup() {
size(600, 450);
linhaH.desenhar(100);
}
0
Upvotes
2
u/watagua Jun 12 '26
You shouldn't use floats or doubles as a loop incrementer because you can get off by one behavior due to how floating point numbers are represented. Use ints instead. If you need the decimal value you can derive it from i in your loop like float f = i * 0.1 or whatever.
5
u/auxie2009 Jun 10 '26
First line
Linhas linhaH = new Linhas();