UnsatisfiedLinkError using Serial port from Processing in Eclipse

放肆的年华 提交于 2020-01-06 05:59:08

问题


I have a processing program that is supposed to read the data from a serial port created by an arduino uno. I got the program to work perfectly in Processing but not in Eclipse. I added core.jar serial.jar and jssc.jar to my java project's build path, but am still getting an error calling the port with Serial.list()[0].

I have seen similar questions on here, but none have helpful answers. I don't know if I'm missing something or need to import a different jar file to my build path.

import processing.core.PApplet;
import processing.serial.*; 

public class Processing extends PApplet {

    public Processing() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        PApplet.main("Processing");
    } 

    Serial myPort;
    String val;

    public void setup() {
        myPort = new Serial(this, Serial.list()[0], 9600);
    }

    public void draw() {
        if ( myPort.available() > 0) {
            val = myPort.readString();
        } 

        if (val != null) {
            println(val);
        }

        delay(250);
    }
}    

Error Message:

java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getSerialPortNames()[Ljava/lang/String;
at jssc.SerialNativeInterface.getSerialPortNames(Native Method)
at jssc.SerialPortList.getWindowsPortNames(SerialPortList.java:309)
at jssc.SerialPortList.getPortNames(SerialPortList.java:298)
at jssc.SerialPortList.getPortNames(SerialPortList.java:182)
at processing.serial.Serial.list(Unknown Source)
at Performance.Processing.setup(Processing.java:44)
at processing.core.PApplet.handleDraw(PApplet.java:2425)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

回答1:


You have added jssc.jar to the Java Build Path which is great, however jssc uses a native c++ library which you need to also reference:

  1. From the Java Build Path > Libraries section
  2. use the arrow to expand jssc.jar and select Native library location
  3. click Edit... on the right hand side and select the folder containing the native c++ library for your OS (in my case that's macosx right now)

Once you apply the changes, the link error will be satisfied.



来源:https://stackoverflow.com/questions/57183705/unsatisfiedlinkerror-using-serial-port-from-processing-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!