Hi everyone, I have been trying to implement the Jinput library 2.0.9 in my robotics project and I have been having issues with polling my gamepad buttons. I use the Jinput getting started tutorial by
- @author TheUzo007
-
http://theuzo007.wordpress.com
My gamepad controller is a Logitech F-310 wired to the computer
My HAT switch position works fine but when it comes to binding the buttons, I can never get the gamepad to work. I keep on getting this error when trying to bind actions to any of my gamepad buttons. It is as if it does not recognize any of my buttons and throws an exception every time I try to push a button.
**Exception in thread “main” java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:359)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at jinputjoysticktestv2.JInputJoystick.getButtonValue(JInputJoystick.java:243)
I use this piece of code to
// Number of buttons.
int numberOfButtons = joystick.getNumberOfButtons();
//getNumberOfButtons();
// Button one on the controller.
boolean joystickButton_1 = joystick.getButtonValue(0);
if(numberOfButtons == 1){
System.out.println("Button 1 is pressed ");
try {
btrc.bluetoothStop();
} catch (IOException e1) {
System.out.println(e1.getMessage());
}}
Can someone please help figure what I am doing wrong, I have been trying to solve the problem for months with no success.
Any help or advice would be much appreciated!
Cheers