NPE & Error using image() in second applet...
in
Programming Questions
•
1 year ago
Hi...
I'm attempting to have a sketch with multiple applets, and I want the second (and or third) applets to draw the contents of a PGraphics buffer. However, I'm getting a NPE error and a blank second canvas. This also seems to be happening when I try to place ANY IMAGE into the draw() method of my second applet, but rect, line, etc. all work.
Here's the Applet/Frame code (besides the declaration and instantiation in setup()
- public class PFrame extends Frame {
- public PFrame() {
- setBounds(SecondScreenOffset, 0, SecondScreenWidth, SecondScreenHeight);
- screen2 = new secondApplet();
- add(screen2);
- removeNotify();
- setUndecorated(false);
- setResizable(false);
- addNotify();
- setLocation(0, 0);
- screen2.init();
- //show();
- setVisible(true);
- }
- }
- public void init() {
- frame.removeNotify();
- frame.setUndecorated(false);
- frame.setResizable(false);
- frame.addNotify();
- super.init();
- }
- public class secondApplet extends PApplet {
- public void setup() {
- size(SecondScreenWidth, SecondScreenHeight);
- background(0);
- }
- public void draw() {
- image(pg, 0, 0); // PGraphics buffer
- }
- }
I'm getting the NullPointerException on Line #33 - the image() call... Here's the stack trace:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:2778)
at processing.core.PApplet.image(PApplet.java:8651)
at bombIR$secondApplet.draw(bombIR.java:424)
at processing.core.PApplet.handleDraw(PApplet.java:1631)
at processing.core.PApplet.run(PApplet.java:1530)
at java.lang.Thread.run(Thread.java:680)
1