merlinvn / controlp5

Automatically exported from code.google.com/p/controlp5
0 stars 0 forks source link

NoSuchMethodException for RadioButton #41

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Run the ControlP5radioButton example or the example sketch below.
2. Press a radio button with the mouse.

--[ EXAMPLE SKETCH BEGIN]---

import controlP5.*;
ControlP5 cp5;

void setup() {
  size(200,200);
  cp5 = new ControlP5(this);
  cp5.addRadioButton("radioButtonName")
  .setPosition(50,50)
  .setSize(100,100)
  .addItem("itemName",0);
}

void draw() {
  background(0);
}

--[ EXAMPLE SKETCH END]---

What is the expected output? What do you see instead?

Although the functionality itself works, you get a NoSuchMethodException in the 
console every time a button is pressed with the mouse. See full error message 
below. The sketch does not crash, but the console gets painted red fast ;-)

What version of the product are you using? On what operating system?

Window XP + Processing 1.5.1 + ControlP5 0.7.2

Please provide any additional information below.

The full console error message is as follows:

java.lang.NoSuchMethodException: ControlP5radioButton.radioButtonName(int)
    at java.lang.Class.getMethod(Class.java:1605)
    at controlP5.RadioButton.controlEvent(Unknown Source)
    at controlP5.Controller.broadcast(Unknown Source)
    at controlP5.Toggle.setState(Unknown Source)
    at controlP5.Toggle.mousePressed(Unknown Source)
    at controlP5.Controller.setMousePressed(Unknown Source)
    at controlP5.ControllerGroup.setMousePressed(Unknown Source)
    at controlP5.ControllerGroup.setMousePressed(Unknown Source)
    at controlP5.ControlWindow.mousePressedEvent(Unknown Source)
    at controlP5.ControlWindow.mouseEvent(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
    at processing.core.PApplet.handleMouseEvent(Unknown Source)
    at processing.core.PApplet.dequeueMouseEvents(Unknown Source)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)

Original issue reported on code.google.com by amnonp5@gmail.com on 22 Apr 2012 at 7:42

GoogleCodeExporter commented 8 years ago
ok noted and reproduced, reflection mistake.

Original comment by soj...@gmail.com on 23 Apr 2012 at 1:13

GoogleCodeExporter commented 8 years ago
The example code misses a method called 'radioButton', which is the name given 
in line 25:
  r = cp5.addRadioButton("radioButton")

just add these lines to the code:
  void radioButton(int i) {
    myColorBackground = color(i * 50,0,0);
  }

then, you can also remove the last statement in the controlEvent() method.
hth

Original comment by spgschm...@gmail.com on 3 May 2012 at 2:24

GoogleCodeExporter commented 8 years ago
 spgschm: Yes, but named callback methods should be optional.

Original comment by ericm...@localprojects.net on 3 May 2012 at 2:26

GoogleCodeExporter commented 8 years ago
probably, however, it is not:
http://code.google.com/p/controlp5/source/browse/trunk/src/controlP5/RadioButton
.java#477

Original comment by spgschm...@gmail.com on 3 May 2012 at 4:11

GoogleCodeExporter commented 8 years ago
Yes indeed, I just wanted to clarify the user's expectation based on past 
releases of ControlP5 (which did not require user-defined named callback 
methods).

Given ControlP5's minimal-config philosophy, this new behavior is probably a 
mistake?

Original comment by ericm...@localprojects.net on 3 May 2012 at 4:16

GoogleCodeExporter commented 8 years ago
Yes, it's a bit confusing.  On the one hand, the doc says:
  "radioButton is of type ControllerGroup, therefore a controllerPlug can't be set. this means that an event from a radioButton can't be forwarded to a method other than controlEvent in a sketch."

On the other hand, there are these methods:
  public RadioButton plugTo(Object theObject)
  public RadioButton plugTo(Object theObject, String thePlugName)
and the abovementioned reflection mechanism.

I'm new to controlP5, so I can't tell how it is supposed to be.

Original comment by spgschm...@gmail.com on 3 May 2012 at 4:30

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
comment 5, ericmika is right here. Its a mistake which will be fixed in the 
next release. 
Controllergroups dont have ControllerPlug callbacks but I made an exception for 
radiobutton and checkbox which also resulted in the discussed mistake.

Original comment by soj...@gmail.com on 15 May 2012 at 12:14

GoogleCodeExporter commented 8 years ago

Original comment by soj...@gmail.com on 18 May 2012 at 5:13

GoogleCodeExporter commented 8 years ago
Thanks! Do you know where we can find the patched code? Looks like the latest 
revision on this site is r60 from april, which predates this fix.

Original comment by ericm...@localprojects.net on 20 May 2012 at 9:46