The method whenPressed(Command) in the type Button is not applicable for the arguments (ToggleIntakeExtend)

We’re trying to bind a command we wrote, named “ToggleIntakeExtend”, to a button on our XboxController class, but the “JoystickButton.whenPressed()” command is throwing the error “The method whenPressed(Command) in the type Button is not applicable for the arguments (ToggleIntakeExtend)”

Here is the code that we have written in RobotContainer.java:

  private void configureButtonBindings() {
      JoystickButton intakeToggle = new JoystickButton(pilot, 5);

      intakeToggle.whenPressed(new ToggleIntakeExtend(intake));
  }

Above this, we create an XboxController called “pilot”

pilot = new XboxController(OIConstants.PILOT_PORT_ID);

Can you share the code for your command? I suspect you’re either not extending Command, or extending the wrong (old command-based) Command class

public class ToggleIntakeExtend extends CommandBase {
  Intake m_intake;
  Pneumatics m_pneumatics;

  boolean toggled = false;

  /** Creates a new ToggleIntakeExtend. */
  public ToggleIntakeExtend(Intake intake) {
    m_intake = intake;
    addRequirements(intake);
    // Use addRequirements() here to declare subsystem dependencies.
  }

  // Called when the command is initially scheduled.
  @Override
  public void initialize() {

  }

  // Called every time the scheduler runs while the command is scheduled.
  @Override
  public void execute() {}

  // Called once the command ends or is interrupted.
  @Override
  public void end(boolean interrupted) {}

  // Returns true when the command should end.
  @Override
  public boolean isFinished() {
    return false;
  }
}

There was some code in here, but we were in the process of rewriting it when I copied this over. The code inside was super simple and doesn’t really matter for the problem we’re having.

What’s the import line for CommandBase?

I like where you’re going, but there’s only one CommandBase. But there are two JoystickButton’s for old and new Command Framework. I suspect JoystickButton is being imported from the old command framework.

@jarb Assuming I’m right, you should remove the old command vendor dep and update your code.

This worked! Thanks!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.