I'm just trying to fill an Object array with Objects using a for loop but for some reason it only fills the first index, all other indices of the array remain null. I've tried referencing other Processing code which does the same thing, and as far as I can tell my code matches? Maybe it's just a small error I'm missing but it has evaded me for like an hour x-x
Here's my Main class:
GalleryRoom[] rooms = new GalleryRoom[12];
int frameCount = 10;
void setup() {
for(int i = 0; i<rooms.length;i++) {
rooms[i] = new GalleryRoom();
rooms[i].setGallery("Prefix", frameCount, i);
print(rooms[0].getCount());
}
}
Printing the getCount method for object 0 of rooms array gives 4111111111116 after iterating through the entire for loop, printing any other object gives NPE.
And my GalleryRoom Object class:
PImage[] images;
int imageCount;
public class GalleryRoom {
public void setGallery(String imagePrefix, int count, int x) {
imageCount = count;
images = new PImage[imageCount];
for (int i = 0; i < imageCount; i++) {
String filename = "Folder"+x+"/"+imagePrefix + nf(i, 4) + ".gif";
images[i] = loadImage(filename);
}
}
public int getCount() {
return imageCount;
}
}