I've created a simple class called
Utility:
Code:class Utility extends Tag {
String utilType;
Utility(PImage ps, String type, float px, float py) {
super(ps, px, py);
utilType = type;
}
void draw() {
imageMode(CENTER);
image(icon, posX, posY);
}
}
Code:class Tag {
PImage icon;
float posX, posY;
Tag(PImage ic, float px, float py) {
icon = ic;
posX = px;
posY = py;
}
void draw() {
imageMode(CENTER);
image(icon, posX, posY);
}
}
If I try to draw an utility, like:
Code:Utility taxiTest;
(...)
taxiImage = loadImage("taxi.png");
taxiTest = new Utility(taxiImage, "taxi", 298.25, 891.5);
(...)
taxiTest.draw();
Everything works great, but if I try to have an Array of utilities, like:
Code:Utility[] taxis = new Utility[6];
(...)
for (int i = 0; i < 6; i++) {
(...)
taxis[i] = new Utility(taxiImage, "taxi", p.x, p.y);
}
(...)
taxis[5].draw();
Causes an
NullPointerException inside the Utility's
draw() method on:
Code:image(icon, posX, posY);
I tried printing
taxi[5].posX, and it works.
Any clues on why I'm having this error?