Riz
Riz

Reputation: 9

processing error ArrayIndexOutOfBoundsException: 32

myPort = new Serial(this, Serial.list()[32], 115200);

what's wrong with that code?

enter image description here

Any suggestion would be appreciated

Upvotes: 0

Views: 143

Answers (1)

George Profenza
George Profenza

Reputation: 51857

Notice the Console output of printArray(Serial.list()).

You have a single serial port "COM4" at index 0.

Any index higher than that (e.g. 32) is out of the valid array index bounds.

The code you're using has a helpful comment:

// if you are a Windows user, please change Serial.list()[your number]

Simply swap the 32 for a 0 and that should do it.

Try to read and understand the code your using: imagine what the code your reading would do and how it run, then actually run it and compare your assumptions to the actual behaviour. Use the Processing reference where you're not familiar. This will help you a lot as a programmer.

For more details see Processing Serial reference.

Upvotes: 1

Related Questions