ControlP5 - java.lang.NullPointerException


Similar to this post, i have an error.
I know the problem is path = controlP5.get(Textfield.class,"File").getText();

But i don’t understand why. All variables are declared at right time… i think :stuck_out_tongue:

It’s not blocking but annoying in the terminal

Thanks for help.

sept. 13, 2019 8:33:12 PM controlP5.ControlBroadcaster printMethodError
GRAVE: An error occured while forwarding a Controller event, please check your code at controlEvent
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
	at controlP5.ControlBroadcaster.broadcast(Unknown Source)
	at controlP5.Controller.broadcast(Unknown Source)
	at controlP5.Button.setValue(Unknown Source)
	at ocm_app.createGui(
	at ocm_app.setup(
	at processing.core.PApplet.handleDraw(
	at processing.awt.PSurfaceAWT$12.callDraw(
	at processing.core.PSurfaceNone$
Caused by: java.lang.NullPointerException
	at ocm_app.controlEvent(
	... 13 more

here is my code:

boolean smartphone = true;
String path;
void setup(){

void draw(){


import controlP5.*; // import controlP5 library
ControlP5 controlP5; // controlP5 object

void createGui() {
  controlP5 = new ControlP5(this);
  int x_control = int(width * 0.01);
  int y_control = int(height *0.95);
  int w_button = int(width * 0.1);
  int h_button = int(width * 0.03);

    .setPosition(x_control, y_control)
    .setSize( w_button, h_button);
    .setPosition(x_control*2 + w_button, y_control)
    .setSize( w_button, h_button);
    .setPosition(x_control*3 + w_button*2, y_control)
    .setSize(w_button, h_button)

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isController()) { 

    print("control event from : "+theEvent.getController().getName());
    println(", value : "+theEvent.getController().getValue());
    if (theEvent.getController().getName()=="open") {     
      path = controlP5.get(Textfield.class,"File").getText();
1 Like

i think the point it that CP5
fires events at startup
BUT at
addButton OPEN
addTextfield FILE
not declared/happened.

move it UP