0

我正在尝试将 jcurses 库导入 IntelliJ,但出现错误。文件 -> 项目结构 -> 模块 -> 导入 jar 文件。

然后在代码中:

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)

有人能指出我的错误在哪里吗?

提前致谢!

4

2 回答 2

0

答案是dll必须和jar文件在同一个目录下。谢谢大家!

于 2017-05-27T10:09:50.830 回答
0

库下载地址

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

库的路径在项目的根目录下

在此处输入图像描述

动态添加库

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);
    }
}
于 2020-10-14T20:37:39.243 回答