We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Camera(...) throws java.lang.NullPointerException
Page Index Toggle Pages: 1
Camera(...) throws java.lang.NullPointerException (Read 1924 times)
Camera(...) throws java.lang.NullPointerException
Jul 29th, 2009, 9:46am
 
Right. I have a class A, which works fine, I can call camera(....) and it works like a charm.

I also have a class B which extends class A. I'm trying to move my camera handling into class B. A instanciates B, and in A's draw() I'm calling a function which refreshes the camera(...) at each frame.

Before the graphics window displays anything I get a java.lang.NullPointerException:


Code:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PApplet.camera(PApplet.java:7570)
at Interaction.handleCamera(Interaction.java:20)
at Interaction.update(Interaction.java:9)
at Robotz.draw(Robotz.java:48)
at processing.core.PApplet.handleDraw(PApplet.java:1426)
at processing.core.PApplet.run(PApplet.java:1328)
at java.lang.Thread.run(Thread.java:613)


Note that I'm using java mode (public class blah blah).

Camera() works well when it's in A, why doesn't it when it's in an instance of B? Also, any suggestions on a more "correct" way of handling the camera tfrom outside my "main" class?

//Edit: seems like any method that has to do with graphics and drawing cannot be called in class B through method A; I just tried calling fill() through B and I got the same error.
Re: Camera(...) throws java.lang.NullPointerException
Reply #1 - Aug 1st, 2009, 8:11am
 
Anyone guys? The question is basically:
Is there a way to draw from a secondary class when programming in the "Java" mode?

I can't extend PApplet ("Can't find a class or type named PApplet") and if I try extending my primary class and drawing through the secondary, I get the
Code:
Exception in thread "Animation Thread" java.lang.NullPointerException
error

//Edit: I managed to extend PApplet (import processing.core.PApplet) but it doesn't solve the problem; I still can't draw from my secondary class, I still get the same error
Re: Camera(...) throws java.lang.NullPointerException
Reply #2 - Aug 4th, 2009, 2:31pm
 
Can you paste your code (at pastebin / nopaste? ) -- Ben
Re: Camera(...) throws java.lang.NullPointerException
Reply #3 - Aug 18th, 2009, 5:32pm
 
pastebin.com/m206be9e7
thank you Ben

Essentially if I try to draw from a second class I fail miserably. If there's no drawing code (box(xxxx)), what I have pasted in pastebin works well
Re: Camera(...) throws java.lang.NullPointerException
Reply #4 - Aug 20th, 2009, 8:28am
 
I'm a bit confused -- you say you have class B that extends class A, but both these classes extend PApplet...I assume Robotz is B, and Game is A.
(By the way, I think Robots.pde should be called Robots.java, and linked  from your primary .pde -- no?)
Still hard to see all the possible ways your null exception could be happening, from that piece of code -- for instance, your camera() call might contain an undefined variable, or your size() might no longer be called at the right time during setup...
If you'd rather not paste your code, I recommend putting println("got to point A!"); , B, C, etc between your lines of code so you can see exactly where it fails, if P5 doesn't hilight it for you.
Or, maybe this information will be enough for someone who has more experience with P5-through-Eclipse / "pure Java" mode.  --Ben
Re: Camera(...) throws java.lang.NullPointerException
Reply #5 - Aug 24th, 2009, 10:25am
 
Ben, I apologise, I should have used pastebin from the beginning and not confuse everyone by rambling on. My pastebin code illustrates exatly what my problem is, if you try running that one you can see the exception. Ignore what I said before, it was confusing.
Page Index Toggle Pages: 1