Null pointer Exception.
in
Programming Questions
•
1 year ago
I'm working on loading the world for a project I'm working on and I get a null pointer when I go to draw the objects. Here is my world code thus far.
- class world {
- world() {
- loadworld();
- }
- private void loadworld() {
- //this will load from a file when I'm done.
- worldOBJ [] world = new worldOBJ [20];
- for (int i = 0; i < world.length;i++) {
- world[i] = new roundOBJ(random(0, width), random(0, height), random(1, 5));
- }
- for (int i = 0; i < world.length;i++) {
- //!! the line below is what is causing the crash
- world[i].drawOBJ();
- }
- }
- }
- //world objects will be moved to it's own separate file when I'm done.
- abstract class worldOBJ {
- protected float x, y;
- worldOBJ(float x, float y) {
- this.x = x;
- this.y = y;
- }
- abstract void drawOBJ();
- }
- class roundOBJ extends worldOBJ {
- private float r;
- private color c;
- //constructor
- roundOBJ(float x, float y, float r) {
- super(x, y);
- this.r = r;
- //this.c = col;
- }
- public void drawOBJ() {
- ellipse(x, y, r, r);
- }
- }
1