Type Serial is ambiguous

I’m new to the Processing language. I am trying to run the code for the Arduino Networked Lamp as detailed in the Getting started with Arduino book. I’ve downloaded the program titled ex06 01 processing and I get the following error when I compile it:

The type Serial is ambiguous
on line 17:

Serial port;

Hi @rototbob,

Please show your imports. The error means, that the Serial class exists more than once in your imported libraries. Best practice is not using asterisks on imports, but rather using the explicit imports for your needs.
If you, for example, use

import processing.serial.*;
import java.io.*;

Serial serial;

It don’t know which Serial to take for Serial, as there are.

processing.serial.Serial and java.io.Serial

Cheers
— mnse

3 Likes

If you know which Serial you want you can explicitly specify to use then e.g.

import processing.serial.*;
import java.io.*;

processing.serial.Serial pSerial;
java.io.Serial ioSerial;

// and create them explicitly where ... are the necessary parameters

pSerial = new processing.serial.Serial(...);
ioSerial = new java.io.Serial(...);
3 Likes

Hello @rototbob,

The code example works in Processing 3.5.4.
There is no java.io.Serial in that Java version to create a conflict.

Processing 4.3 uses a newer Java version that now has this:

And this adds the ambiguity.

This came up in a search:
https://www.reddit.com/r/processing/comments/17c1aqs/type_serial_is_ambiguous/?rdt=57779

This also impacted this code and you can see the fix here:

If you are doing serial communications to an Arduino the choice of which Serial to use is obvious.

Adding a comment to this:

//import java.io.*;

Will yield a helpful tip in the console that suggests what to replace the * with:

:)

1 Like