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 & HelpSyntax Questions › Global Class Costructor or in draw?
Page Index Toggle Pages: 1
Global Class Costructor or in draw?? (Read 474 times)
Global Class Costructor or in draw??
Apr 2nd, 2007, 12:52pm
 
Hello Guys,

when i tried to call the class befor the setup or draw command i got a:

java.lang.NullPointerException

at processing.core.PApplet.registerNoArgs(PApplet.java:758)

at processing.core.PApplet.registerDispose(PApplet.java:749)

at de.bezier.mysql.MySQL.<init>(MySQL.java:83)


BUT when i called «MysqlAnfrage Datenbank= new MysqlAnfrage(this);» within draw it workes. But i would like to call it only once.

Does somebody know where my mistake lies?

Thanks a lot!!!

void setup(){
 
   background(0);
 
   size(XSize, YSize);
   
}


void draw()
{
   MysqlAnfrage Datenbank= new MysqlAnfrage(this);

   Datenbank.getData(startvon,incIntervall);
......
}

class MysqlAnfrage(){

......

}
Re: Global Class Costructor or in draw??
Reply #1 - Apr 2nd, 2007, 1:06pm
 
Before setup() you should state all the elements you are going to use. You can give primitives values here (int, byte, String, float, etc.) but you can't instantiate objects here.

In setup() you get everything prepared, so here you can instantiate objects and all kinds of stuff.

setup() is rather like a class constructor, you give everything values in it. The bit before the constructor is just for stating the contents - not activating the contents.
Re: Global Class Costructor or in draw??
Reply #2 - Apr 2nd, 2007, 1:07pm
 
ok, aaron was faster ... here's my 2 cents:

Code:

MysqlAnfrage Datenbank;

void setup(){
   background(0);
   size(XSize, YSize);
   Datenbank= new MysqlAnfrage(this);
}

void draw()
{
   Datenbank.getData(startvon,incIntervall);
......
}

class MysqlAnfrage(){
......
}


this is not available before the applet is fully created (except inside it's constructor). calling it outside any global functions will not work correctly. the idea is to use setup() for these kind of things ...

F
Re: Global Class Costructor or in draw??
Reply #3 - Apr 2nd, 2007, 1:22pm
 
thanks a lot guys!
Page Index Toggle Pages: 1