so im getting a null pointer exception in my setup when i'm trying to add to an arraylist. i can't see any reason for getting the exception though its probably something stupid im over looking any help would be greatly appreciated. thanks in advance
Code:ArrayList blocks;
PVector[] adjlocs = new PVector[4];
void setup(){
size(960,600);
for(int i = 0; i< 10;i++){
for(int x = 0; x< 10;x++){
blocks.add(new Block(width/2+i*25, height/2+x*25, 25, int(random(0,2))));
}
}
println(blocks.size());
}
void draw(){
background(0);
for(int i=0;i<blocks.size();i++){
Block tempblock = (Block) blocks.get(i);
if(tempblock.activated == false){
tempblock.display();
}
else{
tempblock.nodisplay();
}
}
}
void mouseClicked(){
for(int i=0;i<blocks.size();i++){
Block tempblock = (Block) blocks.get(i);
if(dist(mouseX, mouseY, tempblock.blockx, tempblock.blocky) <=12.5){
tempblock.activated = true;
//println(i+", "+x);
//blockcheck(i);
}
}
}
class Block{
float blockx;
float blocky;
float blocksize;
boolean activated;
int type;
Block(float x, float y, float _blocksize, int _type){
blockx = x;
blocky = y;
blocksize = _blocksize;
activated = false;
type = _type;
}
void nodisplay(){
}
void display(){
if(activated == false){
strokeWeight(1);
if(this.type == 0){
stroke(0,80,250);
}
else if(this.type == 1){
stroke(250,45,45);
}
}
else if(activated == true){
strokeWeight(2);
if(this.type == 0){
stroke(0,80,250);
}
else if(this.type == 1){
stroke(250,45,45);
}
}
if(this.type == 0){
fill(0,80,250,75);
}
else if(this.type == 1){
fill(250,45,45,75);
}
rectMode(CENTER);
rect(blockx, blocky, blocksize,blocksize);
}
}