Go Down

Topic: DUE and nightly build 1.5.6 beta (Read 661 times) previous topic - next topic

kllsamui

i can compile, upload my project,
and when i start terminal it stops after the first output line
and i see error
Code: [Select]

Exception in thread "EventThread COM12" java.lang.NullPointerException
at processing.app.Serial.serialEvent(Serial.java:176)
at jssc.SerialPort$EventThread.run(SerialPort.java:1096)

back to 1.5.5 r2 ?fix? OK

jperedadnr

#1
Feb 20, 2014, 03:21 pm Last Edit: Feb 21, 2014, 12:31 pm by jperedadnr Reason: 1
It happens to me, too, with Arduino Uno or Mega, in Windows 7 and 8.1 64 bits, just by opening the Serial Monitor.

As the exception indicates, the problem is in the Serial.serialEvent method, when reading the serial port. So if you look at the code in the GitHub repo:

Code: [Select]
public synchronized void serialEvent(SerialPortEvent serialEvent) {
   if (serialEvent.isRXCHAR()) {
     try {
       byte[] buf = port.readBytes();
       if (buf.length > 0) {
...
     


as port.readBytes() may return null.

I've tested this outside Arduino IDE, running a simple Java sample with the JSSC library, 2.8.0, and I had the same problem.

An easy solution could be just checking that buf is not null:

Code: [Select]
public synchronized void serialEvent(SerialPortEvent serialEvent) {
   if (serialEvent.isRXCHAR()) {
     try {
       byte[] buf = port.readBytes();
       if (buf!=null && buf.length > 0) {
...
     


Shall I open an Issue on GitHub with this?

Edit: I opened issue #1885, and it's already fixed now! So try the new nightly build, the NPE should not appear anymore.

Jose

Go Up