[ControlP5] Problem with functions hide() / show() ; ''java.lang.NullPointerException''
in
Contributed Library Questions
•
4 months ago
HI friends! I hope someone can help me with this.
I have a control panel with 3 buttons, the buttons are in charge of show() or hide() differents types of controlp5 tools (for example buttons, slides, knobs, etc)
The thing is that all is running well, but i have an error that is annoying.
this is the code of the ControlEvent:
- void controlEvent(ControlEvent theEvent) {
- println("got a control event from controller with name "+theEvent.getController().getName());
- if (theEvent.isController()){
- if (theEvent.controller().name() == "colorA") {
- buttonC = false;
- imag_aVer = imagSet;
- tit = "SETEOS";
- g1.show(); g2.show(); g3.show(); g4.show();
- g5.hide(); g6.hide(); g7.hide(); g8.hide();
- b_C1.hide(); b_C2.hide(); r_C.hide();
- nb_C1.hide(); nb_C2.hide(); nb_C3.hide(); nb_C4.hide();
- nb_C5.hide(); nb_C6.hide(); nb_C7.hide(); nb_C8.hide();
- }
- if (theEvent.controller().name() == "colorB") {
- buttonC = false;
- imag_aVer = imagMed;
- tit = "MEDICIONES";
- g1.hide(); g2.hide(); g3.hide(); g4.hide();
- g5.show(); g6.show(); g7.show(); g8.show();
- b_C1.hide(); b_C2.hide(); r_C.hide();
- nb_C1.hide(); nb_C2.hide(); nb_C3.hide(); nb_C4.hide();
- nb_C5.hide(); nb_C6.hide(); nb_C7.hide(); nb_C8.hide();
- }
- if (theEvent.controller().name() == "colorC") {
- buttonC = true;
- tit = "GRAFICOS";
- g1.hide(); g2.hide(); g3.hide(); g4.hide(); // Groups
- g5.hide(); g6.hide(); g7.hide(); g8.hide();
- b_C1.show(); b_C2.show(); r_C.show(); //Buttons and a range
- nb_C1.show(); nb_C2.show(); nb_C3.show(); nb_C4.show(); //NumberBoxes
- nb_C5.show(); nb_C6.show(); nb_C7.show(); nb_C8.show();
- }
- }
- }
If i only leave the code where i show and hide groups (g1,g2,etc are groups) the error doesnt appear.
The only different thing between the groups and the others is that i create two ControlP5 in the setup, like:
- cp5 = new ControlP5(this); // I create 2, because i use different styles.
- c_p = new ControlP5(this);
- b1 = makeButton(cp5, "colorA", 0, w_barra, b_w, b_h, 0, img_A ); //Menu seteo de valores
- b2 = makeButton(cp5, "colorB", 0, w_barra+h/3, b_w, b_h, 0, img_B ); //Menu muestra valores
- b3 = makeButton(cp5, "colorC", 0, w_barra+2*h/3, b_w, b_h, 0, img_C );
- b_C1 = c_p.addButton("MONITOREAR")
- .setBroadcast(false)
- .setSize(botonx, botony)
- .setPosition( sizex-bordeDer+10, sizey - 2.5*w_barra)
- .setBroadcast(true);
- b_C2 = c_p.addButton("GUARDAR")
- .setBroadcast(false)
- .setSize(botonx, botony)
- .setPosition( sizex-bordeDer+10, sizey - 2*w_barra)
- .setBroadcast(true);
- r_C = c_p.addRange("")
- .setBroadcast(false)
- .setPosition(bordeIzq, w_barra + w/28 + 15*w/1680)
- .setSize(sizex-bordeLateral, w_barra)
- .setHandleSize(20)
- .setRange(0, winSize)
- .setRangeValues(0, winSize)
- .setBroadcast(true)
- .setColorForeground(color(200))
- .setColorBackground(color(100)) ;
- nb_C1 = makeNB("nb_C1", "Temperatura", sizex-bordeDer+10, bordeTecho+4+0*(sizey-bordeLateral)/4, bordeDer-20, 15, 0, #28B0A7);
- nb_C2 = makeNB("nb_C2", "Humedad", sizex-bordeDer+10, bordeTecho+4+1*(sizey-bordeVertical)/4, bordeDer-20, 15, 0, #1A8EBD);
- nb_C3 = makeNB("nb_C3", "CO2", sizex-bordeDer+10, bordeTecho+4+2*(sizey-bordeVertical)/4, bordeDer-20, 15, 0, #E85B4C);
- nb_C4 = makeNB("nb_C4", "Luminosidad", sizex-bordeDer+10, bordeTecho+4+3*(sizey-bordeVertical)/4, bordeDer-20, 15, 0, #FBC76E);
The functions i develop are:
- Button makeButton( ControlP5 cp, String theName, int theX, int theY, int theWidth, int theHeight, int setDefault, PImage[] image) {
- Button button = cp.addButton( theName )
- .setValue( setDefault )
- .setPosition( theX, theY )
- .setSize( theWidth, theHeight )
- .setImages( image )
- ;
- return button;
- }
- Numberbox makeNB( String theName, String theLabel, int theX, int theY, int theWidth, int theHeight, int setDefault, int clr ){
- Numberbox nb = c_p.addNumberbox(theName)
- // .setBroadcast(false)
- .setLabel(theLabel)
- .setPosition(theX, theY)
- .setSize(theWidth, theHeight)
- .setValue(setDefault)
- // .setBroadcast(true);
- nb.setColorBackground(clr);
- nb.setColorLabel(color(10, 20, 30, 140));
- return nb;
- }
Someone???? Thanks in advance!!
1