# Class arrays for my game

**URL:** <https://discourse.processing.org/t/class-arrays-for-my-game/7253>\
**Category:** Coding Questions\
**Created:** [January 6, 2019, 6:44pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253 "2019-01-06T18:44:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernbernm](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bernbernm](https://discourse.processing.org/u/bernbernm)\
**Post date:** [January 6, 2019, 6:44pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/1 "2019-01-06T18:44:52Z")

</div>

Hey, i’m new to processing and programming in general and i’m trying to do a game where there are birds coming for each edge of the screen at random heights with different speeds. The problem with this is that when i try to use an array of that class with PShape involved(for the bird image) the program bugs out when i press the button to get to the game display. My main page looks something like this

```auto
Bird b[i] = new Bird[20]();
PShape n;

void setup() {
  size(1280, 720);
  n = loadShape("piupiu.svg");
  for (int i=0; i<b.length; i++) {
    b[i] = new Bird();
  }
}

void draw() {
  background(0, 255, 0);
  menu();
  if (jogo==true) {
    display();
    b.show();
  }
}

```

My bird class:

```auto
class Bird {

  float x1, x2;
  float xspeed = random(5, 10);
  PShape n;
  PVector v1, v2;

  void show() {
    shape(n,50,60,60,60);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 6, 2019, 6:51pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/2 "2019-01-06T18:51:32Z")

</div>

How exactly does it “bug out”? It should have an error popping up right below your code in a black rectangle.  
Is there any? Can you copy it here?

P.S. When making a post, there’s a little button right above the text field that looks like \</\>  
Please, when putting technical texts, select them and press this button to make them `something like this`, as otherwise the forum’s thing assumes your code is text and makes it fancier by replacing symbols and removing spacebars before things

---

<div class="post-metadata">

**Author:** ![bernbernm](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bernbernm](https://discourse.processing.org/u/bernbernm)\
**Post date:** [January 6, 2019, 7:04pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/3 "2019-01-06T19:04:19Z")

</div>

```auto
NullPointerException

```

But if i do an array of rects lets say they all appear.

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 6, 2019, 7:11pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/4 "2019-01-06T19:11:26Z")

</div>

Uhh, there must be more to this error? There’s usually at least 10 lines, most of which start with the word “at”…

I don’t see anything wrong with the code you posted except that it refers to things that aren’t really in it - maybe the problem is in other parts of the code?

When that error happens, it should highlight the exact line of code where this error happened - what is that line?

---

<div class="post-metadata">

**Author:** ![bernbernm](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bernbernm](https://discourse.processing.org/u/bernbernm)\
**Post date:** [January 6, 2019, 7:12pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/5 "2019-01-06T19:12:09Z")

</div>

```auto
shape(n,100,50,50,50);

```

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 6, 2019, 7:37pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/6 "2019-01-06T19:37:16Z")

</div>

Oh. I guess that’s only because of `n` since nothing else in this line of code could give an error.  
And, you set `n` to `loadShape(“piupiu.svg”)`, so it shouldn’t be `null`, so you shouldn’t get `NullPointerException`… Except if `loadShape(“piupiu.svg”)` fails.

Where is that file `piupiu.svg`? If it’s in your data path or sketch’s path, you might want to use `n = loadShape(dataPath("piupiu.svg"));` or `n = loadShape(sketchPath("piupiu.svg"));` instead.

---

<div class="post-metadata">

**Author:** ![bernbernm](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bernbernm](https://discourse.processing.org/u/bernbernm)\
**Post date:** [January 6, 2019, 11:15pm UTC](https://discourse.processing.org/t/class-arrays-for-my-game/7253/7 "2019-01-06T23:15:43Z")

</div>

It’s on the data folder of my sketch 😕
