Ip5 Error Check event (solved)

Hello Guys,
I’m making an interactive menu, but i have problem reading the event of the menu.

I have 2 accordion menu and one scrollable list. When i select stuff from scrollable list i have no problem, when i open accordion menus processing return thi error:

ontrolP5.ControlBroadcaster printMethodError
GRAVE: An error occured while forwarding a Controller event, please check your code at controlEvent

Caused by: java.lang.ClassCastException: controlP5.Group cannot be cast to controlP5.Controller
at controlP5.ControlEvent.getController(Unknown Source)
at spore_fis_GuiOk_dimensions.controlEvent(spore_fis_GuiOk_dimensions.java:409)
… 32 more

If i remove the Event Control, no error is shown. Here my code

void gug(){
 List l = Arrays.asList("Favorit Light", "Favorit Regular", "Favorit Italic", "Favorit Bold");
  /* add a ScrollableList, by default it behaves like a DropdownList */
 cp5.addScrollableList("Seleziona Font")
     .setPosition(800, 40)
     .setSize(200, 100)
     .setBarHeight(20)
     .setItemHeight(20)
     .setId(1)
     .addItems(l)
  
     // .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
     ;
  






  Group g1 = cp5.addGroup("Parameters")
  .setPosition(0,0)
                .setBackgroundColor(color(0, 64))
               .setBackgroundHeight(150)
               .setId(0)
               ;
  

  cp5.addSlider("pixelDim")
     .setPosition(10,20)
     .setSize(100,20)
     .setRange(2,100)
         .setValue(10)
    .moveTo(g1);
    
     ;
     
       cp5.addSlider("radius")
     .setPosition(10,40)
     .setSize(100,20)
     .setRange(1,30)
     .setValue(10)
    .moveTo(g1);
     ;
     
      cp5.addSlider("forceApplied")
     .setPosition(10,60)
     .setSize(100,20)
     .setRange(-0.5,0.5)
    .moveTo(g1);
     ;
     
       cp5.addSlider("forceRadius")
     .setPosition(10,80)
     .setSize(100,20)
     .setRange(1,500)
    .moveTo(g1);
     ;
     
     cp5.addSlider("kind")
     .setPosition(10,100)
     .setSize(100,20)
     .setRange(1,2)
    .moveTo(g1);
     ;
     //stati di crisi
     
  Group g2 = cp5.addGroup("Stati di crisi")
  .setPosition(200,0)
                .setBackgroundColor(color(0, 64))
               .setBackgroundHeight(150)
               .setId(2)
               ;
                
                
                cp5.addCheckBox("checkBox")
                .setPosition(0, 20)
                .setSize(30, 30)
                .setSpacingRow(5)
                .addItem("Stato1", 0)
               
                .addItem("Stato2", 50)
                
                .addItem("Stato3", 100)
                
                .moveTo(g2);
     ;
               
               
     
     accordion1 =  cp5.addAccordion("acc1")
                .setPosition(240,40)
                 .setWidth(200)
         // bang button        .addItem(g1)
                .addItem(g2);
     
      accordion = cp5.addAccordion("acc")
                .setPosition(40,40)
                 .setWidth(200)
         // bang button        .addItem(g1)
                .addItem(g1);
            
           
}

void gui() {
  hint(DISABLE_DEPTH_TEST);

  cp5.draw();
 
  hint(ENABLE_DEPTH_TEST);
}

public void controlEvent(ControlEvent theEvent) {
  //  println(theEvent.getController().getParent().getName());
//check for the font selected, advise the engine to redraw everything redraw image
  if (theEvent.getController().getId() == 1) {
   
    if(int(theEvent.getController().getValue())==0) {
    redraw=true;
    imageprocees(f0,hm);
    }
    
    else if(int(theEvent.getController().getValue())==1){
    redraw=true;
    imageprocees(f1,hm);
    }
    
    else if(int(theEvent.getController().getValue())==2) {
    redraw=true;
    imageprocees(f2,hm);}
    
    else if(int(theEvent.getController().getValue())==3) {
    redraw=true;
    imageprocees(f3,hm);}
}




}


//
//if ( theEvent.getController().getValue()==0.0 && theEvent.getController() == "Seleziona Font [ScrollableList]")
1 Like

Solution:

the problem is the difference between group and controllers.

void controlEvent(ControlEvent theEvent) {
  if(theEvent.isGroup()) {
    println("got an event from group "
            +theEvent.getGroup().getName()
            +", isOpen? "+theEvent.getGroup().isOpen()
            );
            
  } else if (theEvent.isController()){
    println("got something from a controller "
            +theEvent.getController().getName()
            );
  }
}

adapting this with our pourpose we solve the problem

1 Like