Error shows NullPointerException
in
Programming Questions
•
1 month ago
I wrote this code to process data from a serial port. It could run normally for the first iteration, but after that an error shows "NullPointerException". I searched and found this is sometimes associated with problems in initialization. But I still can't fix this... I have just started to learn coding.
I would appreciate it if anyone could help me out here. Thank you for your time!
here is the code:
import processing.serial.*;
String rawData =null ;
String[] data = null;
float[] num = null;
Serial myport;
void setup(){
myport = new Serial(this,Serial.list()[0],9600);
}
void draw(){
if(myport.available()>0){
rawData = myport.readStringUntil(' ');
data = split(rawData,',');
num = float(data);
// this is where the error highlights
println(num);
}
}
1