# nullpointer exception

**URL:** <https://forum.arduino.cc/t/nullpointer-exception/388642>\
**Category:** Programming\
**Created:** [May 28, 2016, 11:32am UTC](https://forum.arduino.cc/t/nullpointer-exception/388642 "2016-05-28T11:32:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LisaM](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@LisaM](https://forum.arduino.cc/u/LisaM)\
**Post date:** [May 28, 2016, 11:32am UTC](https://forum.arduino.cc/t/nullpointer-exception/388642/1 "2016-05-28T11:32:37Z")

</div>

I'm using Arduino and Processing to create an instrument that responds to touch by lighting LEDs and playing MP3 files.

My code was working until today. I don't know why it's not working. I'm a beginner with this stuff so I don't know how to fix it or what went wrong.

I'm getting a Null Pointer exception error highlighting the 'while (port.available () \> 0 ){'

I tried changing the value to 1 and also tried putting a writing while (port.available () \> 0 );{  
but neither worked.

```cpp
  while (port.available () > 0) {
    int myChar = (port.read());
    if (myChar == 'A') {                  //CHECK ARDUINO INPUT AND PLAY CORRESPONDING TONES
      player_1.cue(0);                    
      player_1.play();
    }

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [May 28, 2016, 1:04pm UTC](https://forum.arduino.cc/t/nullpointer-exception/388642/2 "2016-05-28T13:04:03Z")

</div>

Are you sure that the Arduino is sending the correct values ? Can you print them in Processing to check ?  
How about posting your complete Arduino code as this is an Arduino forum.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 28, 2016, 1:53pm UTC](https://forum.arduino.cc/t/nullpointer-exception/388642/3 "2016-05-28T13:53:57Z")

</div>

> but neither worked.

The problem is not that the available() call method has a problem. It is that port is a NULL pointer.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:55pm UTC](https://forum.arduino.cc/t/nullpointer-exception/388642/4 "2021-05-05T21:55:04Z")

</div>


