我完全按照the steps in this tutorial设置了JInput 2.0.7,但我一直收到以下错误:
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)
这似乎是类本身的一个错误,但我没有在其他任何地方看到过这个错误,这篇文章也是去年发布的。这是JInput的问题,还是我做了什么?
答案 0 :(得分:0)
at net.java.games.input.OSXHIDDevice.addElements(OSXHIDDevice.java:163)
这是发生错误。这似乎是一个内部JInput错误。 您必须修改JInput的源代码才能解决此问题。
查看源代码。这是抛出异常的方法。
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);
}
}
在这一行中,properties.get(kIOHIDElementKey)返回一个String。 String无法转换为Object []:
Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);