ArrayList - would like to get it printed in a window

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:

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.

Hi slijavan,

You need to initialize it like this:

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.

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());