目前我有一个N-Trig Multitouch面板挂接到事件文件/dev/input/event4,我正在尝试访问它。我已经在java.library.path中包含了所有本地的等等,但即使是超级用户也会出现这个错误。例外:
java.io.IOException: Invalid argument
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.FileDispatcherImpl.read(FileDispatcherImpl.java:46)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:197)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:149)
at com.dgis.input.evdev.EventDevice.readEvent(EventDevice.java:269)
at com.dgis.input.evdev.EventDevice.access$1(EventDevice.java:265)
at com.dgis.input.evdev.EventDevice$1.run(EventDevice.java:200)
EVENT: null
Exception in thread "Thread-0" java.lang.NullPointerException
at com.asdev.t3.Bootstrap$1.event(Bootstrap.java:41)
at com.dgis.input.evdev.EventDevice.distributeEvent(EventDevice.java:256)
at com.dgis.input.evdev.EventDevice.access$2(EventDevice.java:253)
at com.dgis.input.evdev.EventDevice$1.run(EventDevice.java:201)
有人知道为什么会发生这种事吗?感谢
我在项目的问题页面上回答了这个问题。
作者:attilapara
嗨,我试着在树莓派上使用这个库,结果也一样例外,但我找到了问题的根源,并设法让它工作起来。基本上,问题是这个库仅为64位CPU/OS编写。说明:input_event结构如下(来源):
struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; };
这里我们有timeval,它有以下成员(来源):
time_t tv_sec seconds suseconds_t tv_usec microseconds
这两种类型在32位和64位上的表示方式不同系统
解决方案:
- 将input_event的大小从24字节更改为16字节:
更改源文件的第34行evdev java/src.com/dgis/input/evdv/InputEvent.java来自:
public static final int STRUCT_SIZE_BYTES = 24; to this: public static final int STRUCT_SIZE_BYTES = 16; Change the parse function in the same source file as follows: public static InputEvent parse(ShortBuffer shortBuffer, String source) throws IOException { InputEvent e = new InputEvent(); short a,b,c,d; a=shortBuffer.get(); b=shortBuffer.get(); //c=shortBuffer.get(); //d=shortBuffer.get(); e.time_sec = (b<<16) | a; //(d<<48) | (c<<32) | (b<<16) | a; a=shortBuffer.get(); b=shortBuffer.get(); //c=shortBuffer.get(); //d=shortBuffer.get(); e.time_usec = (b<<16) | a; //(d<<48) | (c<<32) | (b<<16) | a; e.type = shortBuffer.get(); e.code = shortBuffer.get(); c=shortBuffer.get(); d=shortBuffer.get(); e.value = (d<<16) | c; e.source = source; return e; }