# Clearing an ArrayList

**URL:** https://discourse.processing.org/t/clearing-an-arraylist/3697
**Category:** Libraries
**Created:** [September 20, 2018, 3:04pm UTC](https://discourse.processing.org/t/clearing-an-arraylist/3697 "2018-09-20T15:04:11Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [September 20, 2018, 4:50pm UTC](https://discourse.processing.org/t/clearing-an-arraylist/3697/8 "2018-09-20T16:50:06Z")

</div>

Interesting can’t see the IndexOutOfBoundsException exception 🙂  
What is also interesting is you get the same exception using `clear()` or the loop, so use `clear()`

What is interesting is the `java.lang.reflect.InvocationTargetException`. This is caused when it can’t find the method to execute.

Looking at the rest of the stack trace I see

```auto
	at dome_004$ControlFrame.setup(dome_004.java:356)
	at processing.core.PApplet.handleDraw(PApplet.java:2404)

```

It seems that the PApplet’s draw() method is being called before the controlFrame setup() which probably means that the toggle switch is not been configured so the ringToggle method is not been ‘set’. Looking at the rest of the trace seems to confirm this

```auto
Caused by: java.lang.NullPointerException
	at dome_004$ControlFrame.ringToggle(dome_004.java:468)

```

Sorry for qll the seems and maybes I am not familiar with the inner workings of controlP5, being more used to G4P.

There is another possibility and that is because your cp5 toggle is on a cp5 control frame, effectively a second window. Again depending on controlP5 implements the ControlFrame. If it does it in a similar manner to G4P then each window has its own event handling thread so they can get out of sync.

You might try and read this [discussion](https://discourse.processing.org/t/g4p-gtextarea-glabel-object-update-across-windows-cause-app-crash/2854).

---

_[View the full topic](https://discourse.processing.org/t/clearing-an-arraylist/3697)._
