0

I've followed the steps in this tutorial exactly to set up JInput 2.0.7, but I keep getting the following error:

Loading: net.java.games.input.OSXEnvironmentPlugin
java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
    at net.java.games.input.OSXHIDDevice.addElements(OSXHIDDevice.java:163)
    at net.java.games.input.OSXHIDDevice.addElements(OSXHIDDevice.java:172)
    at net.java.games.input.OSXHIDDevice.getElements(OSXHIDDevice.java:178)
    at net.java.games.input.OSXEnvironmentPlugin.createControllersFromDevice(OSXEnvironmentPlugin.java:226)
    at net.java.games.input.OSXEnvironmentPlugin.enumerateControllers(OSXEnvironmentPlugin.java:262)
    at net.java.games.input.OSXEnvironmentPlugin.<init>(OSXEnvironmentPlugin.java:136)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
    at net.java.games.input.test.ControllerReadTest.<init>(ControllerReadTest.java:253)
    at net.java.games.input.test.ControllerReadTest.main(ControllerReadTest.java:302)

It seems to be an error with the class itself, but I haven't seen this error anywhere else, and the article was published just last year as well. Is this a problem with JInput, or did I do something wront?

Kiran
  • 617
  • 6
  • 20

1 Answers1

0
at net.java.games.input.OSXHIDDevice.addElements(OSXHIDDevice.java:163)

this is were the error occurs. this seems to be an internal JInput error. You'd have to modify the source code of JInput to fix that.

Looked into the source code. This is the method that throws the exception.

private final void addElements(List elements, Map properties) {
    Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);
    if (elements_properties == null)
        return;
    for (int i = 0; i < elements_properties.length; i++) {
        Map element_properties = (Map)elements_properties[i];
        OSXHIDElement element = createElementFromElementProperties(element_properties);
        if (element != null) {
            elements.add(element);
        }
        addElements(elements, element_properties);
    }
}

In this line the properties.get(kIOHIDElementKey) returns a String. The String cannot be casted to an Object[]:

Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);
RalleYTN
  • 138
  • 10