# nullPointerExeption

**URL:** <https://discourse.processing.org/t/nullpointerexeption/11741>\
**Category:** Beginners\
**Created:** [May 31, 2019, 3:20pm UTC](https://discourse.processing.org/t/nullpointerexeption/11741 "2019-05-31T15:20:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![programmingNoob](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@programmingNoob](https://discourse.processing.org/u/programmingNoob)\
**Post date:** [May 31, 2019, 3:20pm UTC](https://discourse.processing.org/t/nullpointerexeption/11741/1 "2019-05-31T15:20:27Z")

</div>

I’m working on creating bullets for a remake of [diep.io](http://diep.io), but am new to arrays. I received an error that said nullPointerExeption, and looked it up to find out what I did wrong, but found that it means my array hasn’t been defined. I’ve double checked that I’m running the code, and I define the array’s at the beginning of my code.

```auto
// at the beginning
float[] arrayBulletAngle; 
float[] arrayBulletTotalDistance; 
float[] arrayBulletHealth; 
float[] arrayBulletSpeed; 
int numberOfPlayerBullets = 1; 

// I call this in the draw loop
void createBullet(float angle){ 
  numberOfPlayerBullets ++; 
  arrayBulletAngle[numberOfPlayerBullets] = angle; 
  arrayBulletTotalDistance[numberOfPlayerBullets] = 0; 
  arrayBulletHealth[numberOfPlayerBullets] = bulletHealth; 
  arrayBulletSpeed[numberOfPlayerBullets] = angle; 
}

```

---

<div class="post-metadata">

**Author:** ![LittleBoxes](https://avatars.discourse-cdn.com/v4/letter/l/ee59a6/32.png) [@LittleBoxes](https://discourse.processing.org/u/LittleBoxes)\
**Post date:** [May 31, 2019, 4:13pm UTC](https://discourse.processing.org/t/nullpointerexeption/11741/2 "2019-05-31T16:13:18Z")

</div>

If my memory is good, you must initialize your array or define a size for this array before use it

for example,

`float[] arrayOne = new float[10]; // for a 10 float elements array`  
`int[] arrayTwo = {0,1,2,3,4,5,6,7,8,9}; // for a 10 int elements pre declared array`

without a size declaration, you’v got a NullPointerExeption.  
The size of an array is fixed. If you want an expandable array, List seems much better

---

<div class="post-metadata">

**Author:** ![programmingNoob](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@programmingNoob](https://discourse.processing.org/u/programmingNoob)\
**Post date:** [May 31, 2019, 4:45pm UTC](https://discourse.processing.org/t/nullpointerexeption/11741/3 "2019-05-31T16:45:39Z")

</div>

Thank you so much! That explains my problems.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 31, 2019, 4:59pm UTC](https://discourse.processing.org/t/nullpointerexeption/11741/4 "2019-05-31T16:59:04Z")

</div>

- [Forum.Processing.org/two/discussion/8071/why-do-i-get-a-nullpointerexception](http://Forum.Processing.org/two/discussion/8071/why-do-i-get-a-nullpointerexception)
- [Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays](http://Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays)
- [Forum.Processing.org/two/discussion/8081/from-several-arrays-to-classes](http://Forum.Processing.org/two/discussion/8081/from-several-arrays-to-classes)
