So I have been getting this error that is stated in the title and I have looked around a bit. The problem often seems to be a library or an nVidea driver however I am not using any nVidea drivers. So I am at a bit of a loss as of why I am getting this error. It only occurs in the code below.
ArrayList<PVector> Days = new ArrayList<PVector>(0);
int spread = 50;
int cols, rows;
void setup() {
size(540, 960);
cols = width/spread;
rows = height/spread;
for (int i = 0; i < cols; i++) {
for (int j = 0; i < rows; j++) {
int x = i * spread;
int y = j * spread;
Days.add(new PVector(x, y));
}
}
}
void draw() {
for (int i = Days.size() - 1; i >= 0; i--) {
float x = ((PVector)Days.get(i)).x;
float y = ((PVector)Days.get(i)).y;
fill(255);
stroke(0);
ellipse(x, y, 50, 50);
}
}
I am following the example here http://learningprocessing.com/examples/chp16/example-16-06-Grid
and tried to adapt it for my own use, I am guessing something there went wrong.
1 Like
Restart your computer please
Sometimes only a hickup
This time I got a new error after running it for a little while
“OutOfMemoryError: You may need to increase the memory settings in Prefrences”
could this be because one of the loops didn’t stop looping? It highlighted line 20
Days.add(new PVector(x, y));
Make This ArrayList<PVector> Days = new ArrayList();
Without 0 and with telling the Arraylist the type of its elements
1 Like
Still gives me the same error sadly
Jep I messed up making one of the loops, thanks for taking the time to sort that out for me
1 Like
Technically:
PVector pv = Days.get(i);
(No need to tell (cast) PVector because you told it the Arraylist now when declaring it)
ellipse(pv.x,pv.y, ......
1 Like
O yea true, thanks for the tip
my version with comments
ArrayList<PVector> days = new ArrayList(); // lists start with lower case
void setup() {
size(540, 960);
int spread = 50; // make variables local when possible
int cols, rows;
cols = width/spread;
rows = height/spread;
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
float x = i * spread + spread/2+18; // centering the grid
float y = j * spread + spread/2+5;
days.add(new PVector(x, y));
}
}
}
void draw() {
fill(255);
stroke(0);
for (PVector pv : days) { // short form of for-loop
ellipse(pv.x, pv.y, 50, 50);
}
}
//
2 Likes