I'm trying to use Eclipse IDE, but I'm experiencing troubles with doing nice OOP.
following code in Processing IDE will do it just fine:
(file DrawingImages):
Background bg;
PImage a;
void setup()
{
size(1000,600);
bg = new Background("pic.jpg");
a = loadImage("pic.jpg");
}
void draw()
{
bg.display();
}
(file Background):
class Background
{
PImage img;
int posX, posY;
public Background(String filename)
{
posX = 0;
posY = 0;
img = loadImage(filename);
}
public void display()
{
image(img,posX,posY);
}
}
now in Eclipse i have to import processing...the first class:
import processing.core.*;
public class Panorama extends PApplet
{
Background bg;
PImage a;
public void setup()
{
size(1000,600);
bg = new Background("pic.jpg");
a = loadImage("pic.jpg");
}
public void draw()
{
bg.display();
}
}
(and the constructor class...)
import processing.core.*;
public class Background extends PApplet
{
public PImage img;
private int posX, posY;
public Background(String filename)
{
posX = 0;
posY = 0;
img = loadImage(filename);
}
public void display()
{
image(img,posX,posY);
}
}
}
This will not produce a compilation error, but folloing runtime errors:
Error while running applet.
java.lang.NullPointerException
at processing.core.PApplet.image(PApplet.java:7567)
at Background.display(Background.java:24)
at Panorama.draw(Panorama.java:34)
at processing.core.PApplet.handleDisplay(PApplet.java:1463)
at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
at processing.core.PApplet.run(PApplet.java:1560)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at processing.core.PApplet.image(PApplet.java:7567)
at Background.display(Background.java:24)
at Panorama.draw(Panorama.java:34)
at processing.core.PApplet.handleDisplay(PApplet.java:1463)
at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
at processing.core.PApplet.run(PApplet.java:1560)
at java.lang.Thread.run(Unknown Source)
I don't know what i'm doing wrong... can anyone please help me out?
Thanks in advance