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 & HelpIntegration › class strucure in Eclipse
Page Index Toggle Pages: 1
class strucure in Eclipse (Read 893 times)
class strucure in Eclipse
Apr 25th, 2006, 8:18am
 
I am trying to move a processing program over to Eclipse and I am having some troubles with basic class structure.

Here is a test script to show the problem I am having

First:

import processing.core.*;
import processing.opengl.*;

public class test4 extends PApplet {

testTest t1;

public void setup() {


size(200, 200);


t1 = new testTest();

}

public void draw() {


background(255);


fill(120,120,0);
               //t1.update();

}

}

The above script works fine but if I uncomment “t1.update()” and have this script run:

import processing.core.*;
import processing.opengl.*;

public class testTest extends PApplet {

public testTest() {

}

public void update() {


 fill(120,120,0);


 rect(20,20,20,20);

}

}

I get this error:

java.lang.NullPointerException

at processing.core.PApplet.fill(PApplet.java:7006)

at testTest.update(testTest.java:8)

at test4.draw(test4.java:13)

at processing.core.PApplet.handleDisplay(PApplet.java:1330)

at processing.core.PGraphics.requestDisplay(PGraphics.java:535)

at processing.core.PApplet.run(PApplet.java:1146)

at java.lang.Thread.run(Unknown Source)
Error while running applet.

All I am doing is having a different class do the drawing to screen – the above set up works in processing so why not of Eclipse?

Thanks

4dplane
Re: class strucure in Eclipse
Reply #1 - Apr 25th, 2006, 12:44pm
 
The reason you are getting a null pointer exception is that testTest hasn't been properly initialized as an applet. But unless you need two separate processes with two separate windows, you only need one of your classes to extend PApplet. The other (i.e. "testTest") should receive a PApplet object reference from the class that is acting as "parent".

The following will work, note the use of "this" to provide testTest with a reference to the parent PApplet object.

Code:
import processing.core.*;
import processing.opengl.*;

public class test4 extends PApplet {

testTest t1;

public void setup() {
size(200, 200);
t1 = new testTest(this);
}

public void draw() {
background(255);
fill(120,120,0);
t1.update();
}
}


import processing.core.*;
import processing.opengl.*;

public class testTest {
PApplet p;

public testTest(PApplet _p) {
p=_p;
}

public void update() {
p.fill(120,120,0);
p.rect(20,20,20,20);
}
}
Re: class strucure in Eclipse
Reply #2 - Apr 25th, 2006, 6:30pm
 
Ahh! - what would I do without people like you?

Thanks for the input,

4dplane

sidenote - above you posted my code in proper format, what <><> command does this?
Re: class strucure in Eclipse
Reply #3 - Apr 25th, 2006, 6:54pm
 
It's {code} {/code} except with square brackets []
Re: class strucure in Eclipse
Reply #4 - Mar 28th, 2008, 5:44am
 
thank you for being so intelligent.  I had a similar mindcrappity smack going on.
Page Index Toggle Pages: 1