Hi,
Am I missing something to load an image in a extended class?
the next example works when the class "Module" is a normal class, but fails when class "Module" is an extended class:
I got this error in an extended class: Exception in thread "Animation Thread" java.lang.NullPointerException
Am I missing something to initialize?
thank you a lot
import org.gicentre.utils.multisketch. *;
// Path
PImage imagen;
String path = sketchPath;
String dpath =dataPath("");
Module[] mods;
int count=201;
void setup(){
size(640, 360);
println("DP"+dataPath(""));
dpath =dataPath("");
mods = new Module[count];
println("DP"+dpath);
int cont = 0;
for (int y = 1; y <=5; y++) {
for (int x = 1; x <=3; x++) {
cont=cont+1;
mods[cont] = new Module("name"+x+":"+y, "photo.jpg",50*x,60*y);
}}
}
void draw() {
// background(0);
for (int i = 1; i < (15); i++) {
println("i"+i);
mods[i].update();
println("updated");
mods[i].draw();
println("drawed");
ellipse(120,120,40,40);
}
}
class Module extends EmbeddedSketch{
String nombre;
String archivo;
int xtemp;
int ytemp;
PImage imagen;
//PImage imagen;
Module(String nombre_, String archivo_, int xtemp_, int ytemp_) {
nombre= nombre_;
archivo=archivo_;
xtemp=xtemp_;
ytemp=ytemp_;
}
void setup(){
};
void update() {
String route=dpath+"/"+archivo; //directory path plus file
println("route"+route); // the path to the image
imagen=loadImage(route); //here the route is correct
image(imagen,40,60); //here the errorr null pointer exception appears when it is in an extended class...
}
void draw() {
ellipse(20,20,50,50);
}
}
1