# Serial Event null pointer exception

**URL:** <https://discourse.processing.org/t/serial-event-null-pointer-exception/13275>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [August 9, 2019, 2:25pm UTC](https://discourse.processing.org/t/serial-event-null-pointer-exception/13275 "2019-08-09T14:25:21Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [August 9, 2019, 3:20pm UTC](https://discourse.processing.org/t/serial-event-null-pointer-exception/13275/2 "2019-08-09T15:20:21Z")

</div>

> [@l-arc-en-ciel](#):
>
> `coordinates.remove(0);`

You’re invoking method **remove()** inside **serialEvent()** callback, which is run by the Serial’s Thread btW! 🧵

That is a big no, no! You’re better off just using **readString()** inside **serialEvent()** to grab the received String. 📿

However, parse that as JSONObject within **draw()** instead. 🖼

You can use the **noLoop()**/**redraw()** approach for a much easier event management: 💡

> **[redraw() / Reference](https://processing.org/reference/redraw_.html)**
>
> Executes the code within draw() one time. This functions allows the program to update the display window only when necessary, for example when an event registered by mousePressed() or

> [@Map function worked in Processing 2 and early 3.. But broke in 3.5.3. Need guidance](https://discourse.processing.org/t/map-function-worked-in-processing-2-and-early-3-but-broke-in-3-5-3-need-guidance/11371/2):
>
> Mutating the sketch’s main canvas outside the “Animation Thread” crashes the program! boomCallback serialEvent() is run by the Serial’s Thread btW. warningSo even calling something like background() can be fatal! fearfulActually, due to a bad design, any Processing function which depends on color() will get wrong results when they’re multithreading invoked! bugSo any canvas mutating operations should be moved to draw() or called by it. face_with_monocleHere’s a post link for…

---

_[View the full topic](https://discourse.processing.org/t/serial-event-null-pointer-exception/13275)._
