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

发布于 2024-12-05 11:59:58 字数 459 浏览 0 评论 0原文

我尝试了很多选项来解决这个问题,但找不到解决方案。我也创建了头文件和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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的那抹悲凉 2024-12-12 11:59:58

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

以下代码:

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

Could it be that your static initializer is failing.

The following code:

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

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

produces the output:

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.

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.

狼性发作 2024-12-12 11:59:58

未构建二进制文件时会出现错误“无法找到或加载主类...”。单击项目,关闭自动构建。然后单击项目并构建全部。然后开启自动构建。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文