Why do I get a NullPointerException

Hi @LauraDob,

I think I can see the error here. (Your insistance on COM5 being the right port was a good hint). Since you are certain that you want to reference “COM5” then you must refer to “COM5” via the address Serial.list()[index] (here the index is the value for “COM5” that is printed when you check the console following this line: printArray(Serial.list());

The console should tell you which Serial.list()[index to put].

(on my computer it prints: [0] “COM3”, it should list others like COM 5 also…)

So try changing your reference argument in Serial to something like this…

myPort = new Serial(this, Serial.list()[place the index # here], 9600);

Hope this helps.

Cordially,
JS

PS: Check the example files for the Serial Library for more hints on syntax for the Serial library.

1 Like