Hello,
See the reference:
Checking for a null (before data.substring()) will eliminate the error:
void serialEvent (Serial myPort) {
// starts reading data from the Serial Port
// reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
data = myPort.readStringUntil('.'); // Read the string from the COM port (using '.' as the end-of-string delimiter
if (data != null)
{
println(data);
data = data.substring(0, data.length()-1); // determine the length of the string
}
}
Tested with an Arduino sending data.
:)