首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当尝试在IntelliJ中导入时,jcurse会出错

当尝试在IntelliJ中导入时,jcurse会出错
EN

Stack Overflow用户
提问于 2017-05-26 13:50:25
回答 2查看 237关注 0票数 0

我试图将jcurses库导入到IntelliJ,但得到了一个错误。文件->项目结构->模块->导入jar文件。

然后在代码中使用

代码语言:javascript
复制
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)

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

提前感谢!

EN

回答 2

Stack Overflow用户

发布于 2017-05-27 10:09:50

答案是dll必须与jar文件位于同一个目录中。感谢大家!

票数 0
EN

Stack Overflow用户

发布于 2020-10-14 20:37:39

Libray下载网址

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

库的路径位于项目的根目录中。

动态添加库

代码语言:javascript
复制
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);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44203328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档