I’ve got a project using jInput for gamepad input. I rolled my own class to provide polling-update functionality (a thread that polls the controllers constantly for a change in button state) so that my classes can be notified when the state of one of the buttons changes on the gamepad. The problem is, that a few of my users are having troubles where a NullPointerException is being thrown (apparently) from the poll() method.
Here is the stacktrace:
java.lang.NullPointerException
at net.java.games.input.DIControllers.getNextDeviceEvent(DIControllers.java:62)
at net.java.games.input.DIAbstractController.getNextDeviceEvent(DIAbstractController.java:62)
at net.java.games.input.AbstractController.poll(AbstractController.java:219)
at com.astruyk.freetar.input.Gamepad.updateButtonStates(Gamepad.java:123)
at com.astruyk.freetar.input.GamepadPoller.startPolling(GamepadPoller.java:91)
at com.astruyk.freetar.editor.MusicEditor.initButtonConfig(MusicEditor.java:561)
at com.astruyk.freetar.editor.MusicEditor.<init>(MusicEditor.java:111)
at com.astruyk.freetar.editor.MusicEditor.main(MusicEditor.java:2093)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
the com.astruyk.freetar.* classes are my own. The initbuttonconfig() method in the Music Editor calls the GamepadPoller’s startPolling() method, which activates javax.swing.Timer with the following intialization code:
pollTimer = new Timer(POLL_TIME, new ActionListener(){
public void actionPerformed(ActionEvent e){
pollController();
}
});
The pollController() method calls the controllers poll() method (via a wrapper class - Gamepad) , and the exception is being thrown - at least, thats what I think is happening from the stackTrace.
I’m not familiar with the jInput code, and I was wondering if anyone might have any idea what is causing this issue, or what I might do to fix it for my users? For now I guess I’ll just wrap the poll() in a try{}catch block for NullPointerException - but I thought I should report the issue anyways.