# ArrayList - would like to get it printed in a window

**URL:** <https://discourse.processing.org/t/arraylist-would-like-to-get-it-printed-in-a-window/4461>\
**Category:** Coding Questions\
**Created:** [October 14, 2018, 3:37pm UTC](https://discourse.processing.org/t/arraylist-would-like-to-get-it-printed-in-a-window/4461 "2018-10-14T15:37:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sljivan](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sljivan](https://discourse.processing.org/u/sljivan)\
**Post date:** [October 14, 2018, 3:37pm UTC](https://discourse.processing.org/t/arraylist-would-like-to-get-it-printed-in-a-window/4461/1 "2018-10-14T15:37:49Z")

</div>

Hello guys,  
I would like to print list of COM ports list in a window, so user could pick one from the list.  
I used an example I found on the forum, and tried to upgrade it with my request.

I have tryed this:

```auto
int state = 0; 
String result="";
import processing.serial.*;
Serial port;
StringList list = ArrayList(Serial.list);
 
void setup() { 
  size(500, 500);

}
 
void draw() { 
  
  background(255); 
  
    switch (state) 
{
    case 0:
    fill(0);
    text (list,10,100);
    text ("Please enter the number corresponding to the COM port you are sing for the device. \n And press ENTER."+result, 10, 50); 
    break;
 
    case 1:
    fill(255, 2, 2); 
    text ("You have etered: "+result, 100, 200); 
    break;
  }
}
 
void keyPressed() {
 
  if (key==ENTER||key==RETURN) {
 
    state++;
  } else
  result = result + key;
  */
}

```

It keeps showing me an error: “list cannot be resolved or is not a field”.  
It seems I can not define the ArrayList.  
When I tried printArray() it worked just fine, but it only shows the array elements inside the programming console.

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 24, 2018, 7:13pm UTC](https://discourse.processing.org/t/arraylist-would-like-to-get-it-printed-in-a-window/4461/2 "2018-10-24T19:13:49Z")

</div>

Hi slijavan,

You need to initialize it like this:

```auto
StringList list = new StringList(Serial.list());

```

A StringList is not an ArrayList so you can’t initialize it the way you do.  
You are also forgotten the keyword `new` that is used to create a new instance of a class.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 24, 2018, 7:15pm UTC](https://discourse.processing.org/t/arraylist-would-like-to-get-it-printed-in-a-window/4461/3 "2018-10-24T19:15:07Z")

</div>

Okay, first this:

```
StringList list = ArrayList(Serial.list);

```

Error:

> The global variable “list” does not exist

That makes sense, because there is no Serial.list variable – only a Serial.list() method.

```
StringList list = ArrayList(Serial.list());

```

New error:

> The function “ArrayList(String)” does not exist

Right, because you don’t create a new StringList that way – check the reference for StringList. Instead:

```
StringList list = new StringList(Serial.list());

```
