JNI 无法找到或加载主类 - 独特问题
我尝试了很多选项来解决这个问题,但找不到解决方案。我也创建了头文件和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");
}
}
I tried lot of options to fix this , but could not find a solution. I have created the header file and the dll too. Set the class path asd well. Javac command works fine. When I run this file, I get error: Could not find or load main class com.log.jni.example.HelloWorld. Could you please help me. Here is my file.
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");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是您的静态初始化程序失败了。
以下代码:
产生输出:
在“找不到主类”错误之前是否打印出任何堆栈跟踪?在此示例中,找到了该类,但由于静态初始化程序中抛出异常而无法初始化。在您的代码中,可能的怀疑是 System.loadLibrary() 调用失败并出现
UnsatisfiedLinkError
。Could it be that your static initializer is failing.
The following code:
produces the output:
Are there any stack traces printed out before the 'Could not find main class' error? In this example, the class was found but failed to initialize because of the exception thrown in the static initializer. In your code, a likely suspect is that the System.loadLibrary() call fails with an
UnsatisfiedLinkError
.未构建二进制文件时会出现错误“无法找到或加载主类...”。单击项目,关闭自动构建。然后单击项目并构建全部。然后开启自动构建。
The error "Could not find or load main class ..." occurs when the binary file is not built. Click on project, turn off automatic build. Then click on project and build all. Then turn on automatic build.