nullpointer exception
in
Programming Questions
•
1 year ago
import processing.serial.*;
Serial port;
//variables to use
String data = "";
String list[];
int rH = 0;
int rL = 0;
int r1 = 0;
int r2 = 0;
int r3 = 0;
int r4 = 0;
int r5 = 0;
PFont font;
void setup()
{
size (1200,600);
port = new Serial(this,"COM18",9600);
port.bufferUntil('.');
font = loadFont("Arial-Black-200.vlw");
textFont(font,50);
}
void draw()
{
background(0,0,0);
fill(255, 255, 0);
text("T1 T2 L1 L2 L3 L4 L5", 20, 50);
fill(0, 0, 255);
text(hex(rH, 2), 20,120);
text(hex(rL, 2), 140,120);
text(list[2], 400,120);
text(list[3], 560,120);
text(list[4], 720,120);
text(list[5], 880,120);
fill(255, 0, 0);
rect(260, 200, 100, 100);
rect(400, 200, 100, 100);
rect(560, 200, 100, 100);
rect(720, 200, 100, 100);
rect(860, 200, 100, 100);
rH = Integer.parseInt(list[0]);
rL = Integer.parseInt(list[1]);
r1 = rH & 16;
if(r1 == 16){
fill(0, 255, 0);
rect(260, 200, 100, 100);
}
r2 = rL & 16;
if(r2 == 16){
fill(0, 255, 0);
rect(400, 200, 100, 100);
}
r3 = rH & 8;
if(r3 == 8){
fill(0, 255, 0);
rect(560, 200, 100, 100);
}
r4 = rH & 4;
if(r4 == 4){
fill(0, 255, 0);
rect(720, 200, 100, 100);
}
r5 = rL & 32;
if(r5 == 32){
fill(0, 255, 0);
rect(860, 200, 100, 100);
}
}
void serialEvent (Serial port)
{
data = port.readStringUntil('.');
data = data.substring(0, data.length() - 1); //delete full-stop
list = split(data, ',');
}
i just wrote this program and i am getting this error for the one that is in red:
Exception in thread "Animation Thread" java.lang.NullPointerException
at sketch_oct25g.draw(sketch_oct25g.java:56)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
i have been trying to solve this for so long. i am wondering if anyone could help me solve this.
thank you!
1