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 › Problems invoking Processing classes with Eclipse
Page Index Toggle Pages: 1
Problems invoking Processing classes with Eclipse (Read 1162 times)
Problems invoking Processing classes with Eclipse
Mar 17th, 2010, 10:22pm
 
Hello everyone!
This is my first post, nice to meet you all!
I am currently working with Eclipse+Processing. So far the coding is going fine except by something that is quite annoying: every time i am trying to run a class outside the main method i get all kind of errors, something like this:

Exception in thread "Animation Thread" java.lang.NullPointerException
     at processing.core.PApplet.ellipse(PApplet.java:7145)
     at Spot.display(Spot.java:14)
     at MyProcessingClasser.draw(MyProcessingClasser.java:20)
     at processing.core.PApplet.handleDraw(PApplet.java:1425)
     at processing.core.PApplet.run(PApplet.java:1327)
     at java.lang.Thread.run(Thread.java:637)

When I don't make use of any class the Applets run without any kind of problem. Can someone give me a hint?
Specs:
MacBook Pro OSX 10.6.2

Thank you
Emmanuel
Re: Problems invoking Processing classes with Eclipse
Reply #1 - Mar 17th, 2010, 10:24pm
 
and here is the test code:

import processing.core.PApplet;

public class MyProcessingClasser extends PApplet{
     Spot[] balls;

     public void setup(){
       size(200,200);
       smooth();
       noStroke();
       
       balls=new Spot[3];
       for(int i=0;i<balls.length;i++){
         balls[i]=new Spot(random(width),random(height),30);
       }
     }

     public void draw(){
       background(0);
       for(int i=0;i<balls.length;i++){
         balls[i].display();
       }
     }


}


import processing.core.PApplet;

public class Spot extends PApplet{
 float x,y,diameter;
 
 //constructor
 Spot(float xpos, float ypos, float dia){
   x=xpos;
   y=ypos;
   diameter=dia;
 }
 
 public void display(){
   ellipse(x,y,diameter,diameter);
 }
}
Re: Problems invoking Processing classes with Eclipse
Reply #2 - Mar 18th, 2010, 1:45am
 
You should read (or re-read) the Processing in Eclipse page.
Only one class can extend PApplet, which is the main class, creating the sketch's frame.
Other classes must be either inner classes (like in the PDE), thus having direct access to Processing functions, or get the PApplet instance (usually in the constructor) and use it to access Processing functions as methods.
Page Index Toggle Pages: 1