gpt4 book ai didi

java - JNI 无法找到或加载主类 - 独特的问题

转载 作者:太空宇宙 更新时间:2023-11-03 23:34:32 24 4
gpt4 key购买 nike

我尝试了很多选项来解决这个问题,但找不到解决方案。我也创建了头文件和 dll。也设置类路径。 Javac 命令工作正常。当我运行这个文件时,出现错误:无法找到或加载主类 com.log.jni.example.HelloWorld。请你帮助我好吗。这是我的文件。

  public class HelloWorld {
private native void print(String path);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String path="C:\\Capture.pcap";
new HelloWorld().print(path);

}
static {
System.loadLibrary("HelloWorld");
}
}

最佳答案

可能是您的静态初始化程序失败了。

以下代码:

public class Main 
{
static
{
if (true)
throw new Error("Error is here");
}

public static void main(String... args)
{
System.out.println("I am running");
}
}

产生输出:

Exception in thread "main" java.lang.Error: Error is here
at Main.<clinit>(Main.java:22)
Could not find the main class: Main. Program will exit.

在“找不到主类”错误之前是否打印出任何堆栈跟踪?在这个例子中,类被找到但初始化失败,因为静态初始化器抛出了异常。在您的代码中,可能怀疑 System.loadLibrary() 调用失败并出现 UnsatisfiedLinkError

关于java - JNI 无法找到或加载主类 - 独特的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7492257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com