java.lang.UnsatisfiedLinkError:java.library.path中没有usbJava

时间:2015-05-11 20:29:00

标签: java intellij-idea arduino rxtx

我正在尝试使用Java和OSx yosemite连接到我的arduino,但是收到以下错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no usbJava in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at ch.ntb.usb.LibusbJava.<clinit>(LibusbJava.java:366)
    at ch.ntb.usb.USB.init(USB.java:315)
    at org.zu.ardulink.connection.usb.DigisparkUSBConnection.getPortList(DigisparkUSBConnection.java:116)
    at org.zu.ardulink.Link.getPortList(Link.java:217)
    at BlinkLED.main(BlinkLED.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

这是我执行的代码:

public static void main(String[] args) {
        try {
            Link link = Link.getDefaultInstance();
            link = getDigisparkConnection(); // Comment this row if you use just the default connection

            List<String> portList = link.getPortList();
            if(portList != null && portList.size() > 0) {
                String port = portList.get(0);
                System.out.println("Connecting on port: " + port);
                boolean connected = link.connect(port);
                System.out.println("Connected:" + connected);
                Thread.sleep(2000);
                int power = IProtocol.HIGH;
                while(true) {
                    System.out.println("Send power:" + power);
                    link.sendPowerPinSwitch(2, power);
                    if(power == IProtocol.HIGH) {
                        power = IProtocol.LOW;
                    } else {
                        power = IProtocol.HIGH;
                    }
                    Thread.sleep(2000);
                }
            } else {
                System.out.println("No port found!");
            }

        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    private static Link getDigisparkConnection() {
        Set<String> protocolNames = ProtocolHandler.getInstalledProtocolImplementationNames();
        SimpleBinaryProtocol protocol = new SimpleBinaryProtocol();
        if(!protocolNames.contains(SimpleBinaryProtocol.NAME)) {
            ProtocolHandler.installProtocolImplementation(protocol);
        }
        return Link.createInstance("digisparkConnection", SimpleBinaryProtocol.NAME, new DigisparkUSBConnection("digisparkConnection", protocol.getIncomingMessageDivider()));
    }

当我评论第4行(link = getDigisparkConnection();)时,我收到以下错误:

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
    at org.zu.ardulink.connection.serial.SerialConnection.connect(SerialConnection.java:161)
    at org.zu.ardulink.connection.serial.SerialConnection.connect(SerialConnection.java:139)
    at org.zu.ardulink.connection.serial.SerialConnection.connect(SerialConnection.java:227)
    at org.zu.ardulink.Link.connect(Link.java:187)
    at BlinkLED.main(BlinkLED.java:37)

这与本机rxtx lib有关,但我无法解决它。我使用IntelliJ IDEA作为IDE。寻找这个错误,我只找到了linux的答案,但没有关于OSX的答案。 感谢

1 个答案:

答案 0 :(得分:1)

可能的解决方案:

  1. 检查是否所有库都处于最新的稳定版本中。

  2. 检查您的程序是否具有通信抛出串行通信的权限。如果不是,请使用check()命令。