gpt4 book ai didi

java - JNI 找不到 native 方法 (test\Test.java :11: cannot find symbol)

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:10 24 4
gpt4 key购买 nike

我正在关注 this tutorial在 jni 上。

1) Steps 用方法制作了一个test\Test.java文件

public native static int getDouble(int n);

2) 编译生成头文件。 (javac, javah)

3) 创建一个 VC Win32 项目(应用程序类型:DLL)

4) 更改项目属性以包含

%JAVA_HOME%\include;%JAVA_HOME\include\win32\

5) 将 test_Test.h 复制粘贴到 vc 项目中。

6) 构建 > 配置管理器(将平台更改为 x64)

7) 构建解决方案 + 将生成的 .dll 文件复制到 Test.java 类路径

8) 更改 Test.java 以包含调用 native 函数调用。

package test;

public class Test {

public native static int getDouble(int n);

public static void main(String[] args) {
System.loadLibrary("jni_example");

for (int n = 1; n <= 20; n++) {
System.out.println(n + " x 2 = " + getDoubled(n));
}
}
}

9) 再次尝试编译测试出现问题。

D:\workspace\jni_example>ls
jni_example.dll test test_Test.h

D:\workspace\jni_example>javac -classpath . test\Test.java
test\Test.java:11: cannot find symbol
symbol : method getDoubled(int)
location: class test.Test
System.out.println(n + " x 2 = " + getDoubled(n));
^
1 error

当我注释掉 System.out 行时,它当然可以正常工作而无需打印任何内容。

D:\workspace\jni_example>java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)

我哪里出错了?

最佳答案

这是一个拼写错误。 getDoubled()getDouble()

关于java - JNI 找不到 native 方法 (test\Test.java :11: cannot find symbol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16191529/

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