We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello,why this for loop is giving me null pointer exception? Before Setup
PVector PsVerts[] ;
PVector PsVerts2[];
In draw
pushMatrix();
rotateY(-k); //-----------------HERE
translate(Mouse.x, Mouse.y, Mouse2.z+width/2);
rotateY(k); //
fill(26, 59, 45);
beginShape();
for (int i=0; i < 800; i+=10 ) {
println(i);
PVector PsVerts[] = new PVector [i];
PVector PsVerts2[] = new PVector [i];
println(i);
PsVerts[i].x = Mouse.x;
PsVerts[i].y = Mouse.y ;
PsVerts2[i].x = Mouse2.x;
PsVerts2[i].y = Mouse2.y ;
vertex(Mouse.x, Mouse.y, 0);
vertex(Mouse2.x, Mouse2.y, 0);
}
endShape();
popMatrix();
Answers
that's not how you use new()
if you know the number of elements beforehand (800 by the look) than use it in the global definition
and then you have to initialise each of those before you use it
(you can assign values in the new(), save having to set them later)
by tradition variables in java have initialLowerCaseNames, classes have InitialUpperCaseNames, constants are ALL_UPPER_CASE.
Reference: https://processing.org/reference/Array.html
the above is basically the 3rd example there.
thanks