简体   繁体   English

尝试在 IntelliJ 中导入时出现错误

[英]jcurses errors while try to import in IntelliJ

I`m trying to import jcurses library to IntelliJ but get an error.我正在尝试将 jcurses 库导入 IntelliJ,但出现错误。 File -> Project Structure -> Modules -> import jar file.文件 -> 项目结构 -> 模块 -> 导入 jar 文件。

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.答案是dll必须和jar文件在同一个目录下。 Thanks to everyone!谢谢大家!

Libray download url库下载地址

https://sourceforge.net/projects/javacurses/files/javacurses/0.9.5/ 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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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