Null Pointer Exception Error
in
Integration and Hardware
•
1 year ago
Hello,
I am attempting to transfer code written from one Mac to another Mac. This code works on one Mac, but not on the other. I was not the original author of the code, and I have no idea where the error is.
This is the error:
java.lang.NullPointerException
at processing.app.Library.getClassPath(Library.java:298)
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:390)
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197)
at processing.mode.java.JavaBuild.build(JavaBuild.java:156)
at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
at java.lang.Thread.run(Thread.java:655)
This is my code:
import processing.serial.*;
import controlP5.*;
static float PRIMING_MODE = 1.0;
static float TESTING_MODE = 2.0;
static int ACTIVATION_STATE_ACTIVE = 1;
static int ACTIVATION_STATE_INACTIVE = 2;
int PRIMING_THRESHOLD = 90;
int TESTING_THRESHOLD = 100;
int SERIAL_PORT = 0;
int PERCENT_ALLOWANCE_DEFAULT = 12;
int TOY_ACTIVATION_DURATION = 3000;
int ACTIVATION_STATE = ACTIVATION_STATE_INACTIVE;
int THRESHOLD = PRIMING_THRESHOLD;
int PERCENT_ALLOWANCE = 0;
int MAX_REACHED = 0;
float MODE = PRIMING_MODE;
int MIN_READING = 70;
int MAX_READING = 690;
float beginning_of_testing_mode = 0;
float temp_beginning_of_activate = 0;
float beginning_of_activate = 0;
float end_of_activate = 0;
Serial myPort; // The serial port:
PFont myFont; // The display font:
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
int chartHeight = 180;
int chartWidth = 500;
boolean on = false;
ControlP5 controlP5;
Toggle active;
Textlabel debug;
Slider debugSlider;
Chart myChart;
RadioButton radioButton;
void setup() {
size(600,300);
smooth();
myFont = loadFont("ArialMT-18.vlw");
textFont(myFont, 18);
println(Serial.list());
myPort = new Serial(this, Serial.list()[SERIAL_PORT], 9600);
myPort.bufferUntil(lf);
controlP5 = new ControlP5(this);
controlP5.begin(10, 10);
debugSlider = controlP5.addSlider("debug", 0, 1024);
debugSlider.setId(3);
debugSlider.linebreak();
debugSlider.setBroadcast(false);
active = controlP5.addToggle("active");
active.setMode(ControlP5.SWITCH);
active.lock();
active.addListener(new ControlListener() {
public void controlEvent(ControlEvent theEvent) {
myPort.write("1");
}
});
active.setId(4);
myChart = controlP5.addChart("chart", 10, 100, chartWidth, chartHeight);
myChart.setColorBackground(0);
myChart.addDataSet();
myChart.addDataSet();
myChart.setId(1);
ChartDataSet pressureDataSet = myChart.getDataSet(0);
pressureDataSet.setStrokeWeight(2);
pressureDataSet.setColor(color(255,255,255));
ChartDataSet thresholdDataSet = myChart.getDataSet(1);
thresholdDataSet.setColor(color(255,0,0));
ChartDataSet allowanceDataSet = myChart.getDataSet(2);
allowanceDataSet.setColor(color(0,255,0));
controlP5.end();
radioButton = controlP5.addRadioButton("radioButton",500,10);
radioButton.setColorForeground(color(120));
radioButton.setColorActive(color(200));
radioButton.setColorLabel(color(255));
radioButton.setItemsPerRow(1);
radioButton.setSpacingColumn(50);
radioButton.setId(2);
radioButton.setNoneSelectedAllowed(false);
addToRadioButton(radioButton,"PRIMING",int(PRIMING_MODE));
addToRadioButton(radioButton,"TESTING",int(TESTING_MODE));
radioButton.activate("PRIMING");
}
void draw() {
background(0);
}
void addToRadioButton(RadioButton theRadioButton, final String theName, final int theValue ) {
Toggle t = theRadioButton.addItem(theName,theValue);
t.captionLabel().setColorBackground(color(80));
t.captionLabel().style().movePadding(2,0,-1,2);
t.captionLabel().style().moveMargin(-2,0,0,-3);
t.captionLabel().style().backgroundWidth = 46;
t.addListener(new ControlListener() {
public void controlEvent(ControlEvent theEvent) {
toggle_mode();
}
});
}
void serialEvent(Serial p) {
if (on == true) {
inString = p.readString();
String[] tokens = split(trim(inString), "|");
if (tokens.length < 2) return;
// println(tokens);
if (tokens[0].equals("reading")) {
int value = int(tokens[1]);
if (value > MAX_REACHED) {
MAX_REACHED = value;
}
debugSlider.setValue(value);
myChart.addFirst(0, map(value, MIN_READING, MAX_READING, 0, chartHeight));
myChart.addFirst(2, map((THRESHOLD - (THRESHOLD * (PERCENT_ALLOWANCE/100.0))), MIN_READING, MAX_READING, 0, chartHeight));
myChart.addFirst(1, map(THRESHOLD, MIN_READING, MAX_READING, 0, chartHeight));
if (value > (THRESHOLD - (THRESHOLD * (PERCENT_ALLOWANCE/100.0))) ) {
if (active.getState() == false) {
ACTIVATION_STATE = ACTIVATION_STATE_ACTIVE;
beginning_of_activate = millis() - beginning_of_testing_mode;
temp_beginning_of_activate = millis();
active.toggle();
return;
}
} else {
if (ACTIVATION_STATE == ACTIVATION_STATE_ACTIVE) {
ACTIVATION_STATE = ACTIVATION_STATE_INACTIVE;
if (MODE == TESTING_MODE) {
end_of_activate = millis() - beginning_of_testing_mode;
println("data point - [start: " + beginning_of_activate + "], [max: " + MAX_REACHED + "], [end: " + end_of_activate + "]");
// reset threshold to next value
// THRESHOLD = MAX_REACHED;
// reset values for this breach
// MAX_REACHED = 0;
beginning_of_activate = 0;
end_of_activate = 0;
}
}
// if the toy is on, but it's dropped below threshold, and it's been more than TOY_ACTIVATION_DURATION, then disable toy
if (active.getState() == true &&
ACTIVATION_STATE == ACTIVATION_STATE_INACTIVE &&
millis() - temp_beginning_of_activate > TOY_ACTIVATION_DURATION) {
active.toggle();
if (MODE == TESTING_MODE) {
THRESHOLD = MAX_REACHED;
}
return;
}
}
}
myPort.write("2");
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
toggle_on_off();
}
}
}
void toggle_on_off() {
if (on == true) {
on = false;
} else {
on = true;
myPort.write("2");
}
println("toggling " + on);
}
void toggle_mode() {
if (MODE == TESTING_MODE) {
MODE = PRIMING_MODE;
THRESHOLD = PRIMING_THRESHOLD;
PERCENT_ALLOWANCE = 0;
} else {
beginning_of_testing_mode = millis();
MODE = TESTING_MODE;
THRESHOLD = TESTING_THRESHOLD;
PERCENT_ALLOWANCE = PERCENT_ALLOWANCE_DEFAULT;
}
MAX_REACHED = 0;
/*
float f1[] = {};
float f2[] = {};
myChart.updateData(0, f1);
myChart.updateData(1, f2);
*/
}
----------------------------
I'm hoping this is a simple bug, and that it's easy to spot! I'm eternally grateful for any help anyone can offer.
Thanks.
Kayla
I am attempting to transfer code written from one Mac to another Mac. This code works on one Mac, but not on the other. I was not the original author of the code, and I have no idea where the error is.
This is the error:
java.lang.NullPointerException
at processing.app.Library.getClassPath(Library.java:298)
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:390)
at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:197)
at processing.mode.java.JavaBuild.build(JavaBuild.java:156)
at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
at java.lang.Thread.run(Thread.java:655)
This is my code:
import processing.serial.*;
import controlP5.*;
static float PRIMING_MODE = 1.0;
static float TESTING_MODE = 2.0;
static int ACTIVATION_STATE_ACTIVE = 1;
static int ACTIVATION_STATE_INACTIVE = 2;
int PRIMING_THRESHOLD = 90;
int TESTING_THRESHOLD = 100;
int SERIAL_PORT = 0;
int PERCENT_ALLOWANCE_DEFAULT = 12;
int TOY_ACTIVATION_DURATION = 3000;
int ACTIVATION_STATE = ACTIVATION_STATE_INACTIVE;
int THRESHOLD = PRIMING_THRESHOLD;
int PERCENT_ALLOWANCE = 0;
int MAX_REACHED = 0;
float MODE = PRIMING_MODE;
int MIN_READING = 70;
int MAX_READING = 690;
float beginning_of_testing_mode = 0;
float temp_beginning_of_activate = 0;
float beginning_of_activate = 0;
float end_of_activate = 0;
Serial myPort; // The serial port:
PFont myFont; // The display font:
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
int chartHeight = 180;
int chartWidth = 500;
boolean on = false;
ControlP5 controlP5;
Toggle active;
Textlabel debug;
Slider debugSlider;
Chart myChart;
RadioButton radioButton;
void setup() {
size(600,300);
smooth();
myFont = loadFont("ArialMT-18.vlw");
textFont(myFont, 18);
println(Serial.list());
myPort = new Serial(this, Serial.list()[SERIAL_PORT], 9600);
myPort.bufferUntil(lf);
controlP5 = new ControlP5(this);
controlP5.begin(10, 10);
debugSlider = controlP5.addSlider("debug", 0, 1024);
debugSlider.setId(3);
debugSlider.linebreak();
debugSlider.setBroadcast(false);
active = controlP5.addToggle("active");
active.setMode(ControlP5.SWITCH);
active.lock();
active.addListener(new ControlListener() {
public void controlEvent(ControlEvent theEvent) {
myPort.write("1");
}
});
active.setId(4);
myChart = controlP5.addChart("chart", 10, 100, chartWidth, chartHeight);
myChart.setColorBackground(0);
myChart.addDataSet();
myChart.addDataSet();
myChart.setId(1);
ChartDataSet pressureDataSet = myChart.getDataSet(0);
pressureDataSet.setStrokeWeight(2);
pressureDataSet.setColor(color(255,255,255));
ChartDataSet thresholdDataSet = myChart.getDataSet(1);
thresholdDataSet.setColor(color(255,0,0));
ChartDataSet allowanceDataSet = myChart.getDataSet(2);
allowanceDataSet.setColor(color(0,255,0));
controlP5.end();
radioButton = controlP5.addRadioButton("radioButton",500,10);
radioButton.setColorForeground(color(120));
radioButton.setColorActive(color(200));
radioButton.setColorLabel(color(255));
radioButton.setItemsPerRow(1);
radioButton.setSpacingColumn(50);
radioButton.setId(2);
radioButton.setNoneSelectedAllowed(false);
addToRadioButton(radioButton,"PRIMING",int(PRIMING_MODE));
addToRadioButton(radioButton,"TESTING",int(TESTING_MODE));
radioButton.activate("PRIMING");
}
void draw() {
background(0);
}
void addToRadioButton(RadioButton theRadioButton, final String theName, final int theValue ) {
Toggle t = theRadioButton.addItem(theName,theValue);
t.captionLabel().setColorBackground(color(80));
t.captionLabel().style().movePadding(2,0,-1,2);
t.captionLabel().style().moveMargin(-2,0,0,-3);
t.captionLabel().style().backgroundWidth = 46;
t.addListener(new ControlListener() {
public void controlEvent(ControlEvent theEvent) {
toggle_mode();
}
});
}
void serialEvent(Serial p) {
if (on == true) {
inString = p.readString();
String[] tokens = split(trim(inString), "|");
if (tokens.length < 2) return;
// println(tokens);
if (tokens[0].equals("reading")) {
int value = int(tokens[1]);
if (value > MAX_REACHED) {
MAX_REACHED = value;
}
debugSlider.setValue(value);
myChart.addFirst(0, map(value, MIN_READING, MAX_READING, 0, chartHeight));
myChart.addFirst(2, map((THRESHOLD - (THRESHOLD * (PERCENT_ALLOWANCE/100.0))), MIN_READING, MAX_READING, 0, chartHeight));
myChart.addFirst(1, map(THRESHOLD, MIN_READING, MAX_READING, 0, chartHeight));
if (value > (THRESHOLD - (THRESHOLD * (PERCENT_ALLOWANCE/100.0))) ) {
if (active.getState() == false) {
ACTIVATION_STATE = ACTIVATION_STATE_ACTIVE;
beginning_of_activate = millis() - beginning_of_testing_mode;
temp_beginning_of_activate = millis();
active.toggle();
return;
}
} else {
if (ACTIVATION_STATE == ACTIVATION_STATE_ACTIVE) {
ACTIVATION_STATE = ACTIVATION_STATE_INACTIVE;
if (MODE == TESTING_MODE) {
end_of_activate = millis() - beginning_of_testing_mode;
println("data point - [start: " + beginning_of_activate + "], [max: " + MAX_REACHED + "], [end: " + end_of_activate + "]");
// reset threshold to next value
// THRESHOLD = MAX_REACHED;
// reset values for this breach
// MAX_REACHED = 0;
beginning_of_activate = 0;
end_of_activate = 0;
}
}
// if the toy is on, but it's dropped below threshold, and it's been more than TOY_ACTIVATION_DURATION, then disable toy
if (active.getState() == true &&
ACTIVATION_STATE == ACTIVATION_STATE_INACTIVE &&
millis() - temp_beginning_of_activate > TOY_ACTIVATION_DURATION) {
active.toggle();
if (MODE == TESTING_MODE) {
THRESHOLD = MAX_REACHED;
}
return;
}
}
}
myPort.write("2");
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
toggle_on_off();
}
}
}
void toggle_on_off() {
if (on == true) {
on = false;
} else {
on = true;
myPort.write("2");
}
println("toggling " + on);
}
void toggle_mode() {
if (MODE == TESTING_MODE) {
MODE = PRIMING_MODE;
THRESHOLD = PRIMING_THRESHOLD;
PERCENT_ALLOWANCE = 0;
} else {
beginning_of_testing_mode = millis();
MODE = TESTING_MODE;
THRESHOLD = TESTING_THRESHOLD;
PERCENT_ALLOWANCE = PERCENT_ALLOWANCE_DEFAULT;
}
MAX_REACHED = 0;
/*
float f1[] = {};
float f2[] = {};
myChart.updateData(0, f1);
myChart.updateData(1, f2);
*/
}
----------------------------
I'm hoping this is a simple bug, and that it's easy to spot! I'm eternally grateful for any help anyone can offer.
Thanks.
Kayla
1