public static ArrayList<Thing> things = new ArrayList<Thing>();
public static void main(String[] args) {
System.out.println("Creating objects!");
for(int i = 0; i< 5; i++) {
//New Thing (size, location)
things.add(new Thing(5,new PVector(10,10)));
}
PApplet.main(new String[]{"example.Example"});
}
@Override
public void setup() {
size(1000,1000);
background(100);
}
@Override
public void draw(){
for(int i = 0; i<things.size(); i++) {
things.get(i).run();
}
}
}
package example;
import processing.core.*;
import java.util.*;
public class Thing extends PApplet{
private int size;
private PVector location;
public Thing(int size, PVector location) {
this.size = size;
this.location = location;
}
public void run() {
draw();
}
public void draw(PApplet parent) {
int aColour = color(100,50,50);
fill(aColour);
ellipse(500,500,100,100);
}
}
I cannot get the draw method to print something to the screen in the Thing class, the code is here rather than in the main class as there are many things to draw in different classes. I am using netbeans for this and have imported the core library in.
The error message I get when I try to animate in the Thing class is:
Exception in thread "Animation Thread" java.lang.NullPointerException