Hi there,
I got this error
Can anyone help me on this please?
Thank you
lug 19, 2020 5:34:52 PM controlP5.ControlBroadcaster printMethodError
GRAVE: An error occured while forwarding a Controller event, please check your code at automatico
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
at controlP5.ControlBroadcaster.callTarget(Unknown Source)
at controlP5.ControlBroadcaster.broadcast(Unknown Source)
at controlP5.Controller.broadcast(Unknown Source)
at controlP5.Button.setValue(Unknown Source)
at controlP5.Button.activate(Unknown Source)
at controlP5.Button.mouseReleased(Unknown Source)
at controlP5.Controller.setMousePressed(Unknown Source)
at controlP5.ControllerGroup.setMousePressed(Unknown Source)
at controlP5.ControlWindow.mouseReleasedEvent(Unknown Source)
at controlP5.ControlWindow.mouseEvent(Unknown Source)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1436)
at processing.core.PApplet.handleMethods(PApplet.java:1638)
at processing.core.PApplet.handleMouseEvent(PApplet.java:2749)
at processing.core.PApplet.dequeueEvents(PApplet.java:2652)
at processing.core.PApplet.handleDraw(PApplet.java:2493)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
Caused by: java.lang.NullPointerException
at progetto5b.automatico(progetto5b.java:125)
… 25 more
the code i’m working on is
import controlP5.*;
import processing.serial.*;
import java.awt.event.KeyEvent; // imports library for reading the data from the serial port
import java.io.IOException;
ControlP5 cp5;
ControlP5 cp52;
Serial myPort;
boolean on;
int val, iAngle, iDistance, index1=0, index2=0;
String dist, angle, distance, data;
void setup () {
myPort = new Serial(this,"COM5",9600);
//myPort.bufferUntil('.'); // reads the data from the serial port up to the character '.' before calling serialEvent
//println(myPort);
size(700,700);
//noStroke();
cp5 = new ControlP5(this);
cp5.addIcon("icon",10)
.setPosition(100,10)
.setSize(70,50)
.setRoundedCorners(20)
.setFont(createFont("fontawesome-webfont.ttf", 40))
.setFontIcons(#00f205,#00f204)
//.setScale(0.9,1)
.setSwitch(true)
.setColorBackground(color(255,100))
.hideBackground()
;
cp5.addButton("automatico")
.setValue(0)
.setPosition(100,100)
.setSize(200,35);
cp5.addButton("manuale")
.setValue(0)
.setPosition(100,150)
.setSize(200,35);
cp52 = new ControlP5(this);
cp52.addSlider("slider")
.setPosition(100,450)
.setSize(200,20)
.setRange(0,180)
.setValue(0)
;
Textlabel myTextlabelA;
myTextlabelA = cp5.addTextlabel("label1")
//.setText("Angolo manuale:"+slider)
.setPosition(100,250)
.setColorValue(0xffffff00)
.setFont(createFont("Georgia",20))
;
Textlabel myTextlabelB;
myTextlabelB = cp5.addTextlabel("label2")
.setText("Distanza manuale:"+dist)
.setPosition(100,300)
.setColorValue(0xffffff00)
.setFont(createFont("Georgia",20))
;
Textlabel myTextlabelC;
myTextlabelC = cp5.addTextlabel("label3")
.setText("Angolo automatico:"+iAngle)
.setPosition(100,350)
.setColorValue(0xffffff00)
.setFont(createFont("Georgia",20))
;
Textlabel myTextlabelD;
myTextlabelD = cp5.addTextlabel("label4")
.setText("Distanza automatico:"+iDistance)
.setPosition(100,400)
.setColorValue(0xffffff00)
.setFont(createFont("Georgia",20))
;
cp52.hide();
}
void draw () {
background(155);}
void icon(boolean theValue) {
if(theValue==true){on=true;}
else{on=false;}
}
void automatico() {
if(on==true){
cp52.hide();
myPort.write('A');
delay(500);
data = myPort.readStringUntil('.');
data = data.substring(0,data.length()-1);
index1 = data.indexOf(","); // find the character ',' and puts it into the variable "index1"
angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port
distance= data.substring(index1+1, data.length()); // read the data from position "index1" to the end of the data pr thats the value of the distance
// converts the String variables into Integer
iAngle = int(angle);
iDistance = int(distance);}}
void manuale() {
if(on==true){
cp52.show();
//myPort.write(val);
//myPort.readString();
}}
void slider (int slider) {
val=slider;
byte sliderB=byte(val);
myPort.write('P');
myPort.write(sliderB);
}