I
I
Ilya2d2017-11-04 20:07:23
Java
Ilya2d, 2017-11-04 20:07:23

Error when working with COM Port Java JSSC?

Good day! I'm trying to add the JSSC library to the project to read data from the com port, but I see an error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: jssc/SerialPortList
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:133)
Caused by: java.lang.NoClassDefFoundError: jssc/SerialPortList
    at com.traction.game.SerialController.<init>(SerialController.java:7)
    at com.traction.game.Menu.create(Menu.java:13)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Caused by: java.lang.ClassNotFoundException: jssc.SerialPortList
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

SerialController class:
import jssc.SerialPortList;
 
public class SerialController {
    public SerialController() {
        String[] portNames = SerialPortList.getPortNames();
        System.out.println("Ports");
        for(int i = 0; i < portNames.length; i++){
            System.out.println(portNames[i]);
        }
    }
}

calling from:
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Screen;
 
public class Menu extends Game{
    @Override 
    public void create() {
        setScreen((Screen) new Traction());
        
 
        SerialController portController;
        portController = new SerialController();
    }
}

class Game - class of the libGDX library
If the constructor of the SerialController class is replaced by main, then everything is fine. What is the problem, please explain?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question