Error when using GenericHID

I’ve been attempting to add additional controller functionality to my team’s driver station. To do this I imported the GenericHID class from wpilib and attempted to add a rumble function with it.
Upon doing this I got the compiling error
“Cannot make a static reference to the non-static method setRumble(GenericHID.RumbleType, double) from the type GenericHID”

Here is the relelavent sections of code:

import edu.wpilibj.GenericHID;
import edu.wpilibj.GenericHID.RumbleType;
import edu.wpilibj.XboxController;


public void initialize() {
XboxController.setRumble(RumbleType.kLeftRumble, 0.5);
}

I’m not quite sure what you’re trying to do, so I’ll comment specifically on the code snippet provided.

The error is because you’re trying to call setRumble() statically, meaning against the class instead of against an instance of that class. This isn’t a valid use of that method, so it throws an exception. Instead, you need to get an instance of that class (e.g. XboxController controller = new XboxController(1) but be sure to change 1 to the appropriate number for your needs), then call the method from that object (e.g. controller.setRumble(...))

As for the GenericHID import you mentioned, that’s not doing anything. In Java, an import simply makes a symbol available for use, but doesn’t do anything by itself.

1 Like

Thank you for your help, I completely forgot to do that. It is working now.

1 Like

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