简体   繁体   中英

jcurses errors while try to import in IntelliJ

I`m trying to import jcurses library to IntelliJ but get an error. File -> Project Structure -> Modules -> import jar file.

Then in code:

import jcurses.widgets.Window;

class main {

public static void main(String[] args){

    Window win = new Window(800, 600, true, "test");
    win.setVisible(true);
}

Exception in thread "main" java.lang.ExceptionInInitializerError
at jcurses.system.InputChar.<clinit>(InputChar.java:25)
at jcurses.widgets.Window.<clinit>(Window.java:209)
at main.main(main.java:7)
Caused by: java.lang.RuntimeException: couldn't find jcurses library
at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:121)
at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)

Could someone point out where is my mistake?

Thanks in advance!

The answer is that dll must be in the same directory as jar file. Thanks to everyone!

Libray download url

https://sourceforge.net/projects/javacurses/files/javacurses/0.9.5/

The path of the library is in the root directory of the project

在此处输入图片说明

dynamically add the library

import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;

public class LoadLibrary {
    public static void main(String cor[]) throws Exception {
        // Cargando librerias necesarias
        loadLibraryJCourses();
    }
    
    public static void loadLibraryJCourses() throws Exception{
        loadDynamicLibrary(new File("lib/bin/jcourses/").getAbsolutePath(),"libjcurses64");
    }

    private static void addLibraryPath(String pathToAdd) throws Exception {
        final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
        usrPathsField.setAccessible(true);

        //get array of paths
        final String[] paths = (String[]) usrPathsField.get(null);

        //check if the path to add is already present
        for (String path : paths) {
            if (path.equals(pathToAdd)) {
                return;
            }
        }

        //add the new path
        final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
        newPaths[newPaths.length - 1] = pathToAdd;
        usrPathsField.set(null, newPaths);
    }

    private static void loadDynamicLibrary(String pathLibraryDirectory, String libraryName) throws Exception{
        File pathLibraryFile = new File(pathLibraryDirectory);
        addLibraryPath(pathLibraryFile.getAbsolutePath());
        System.loadLibrary(libraryName);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM