JNI方法:正式参数列表的长度不同 [英] JNI method: formal argument lists differ in length
问题描述
我正在尝试修改一个JNI函数,该函数从Java层获取一个字符串参数.
I'm trying to emend a JNI function that takes a string argument from the java layer.
最初,.java文件中的Java代码是:
Initially, the java code from the .java file was:
callJNIMethod();
我正在尝试更改它,以便可以给它一个字符串,如下所示:
I'm trying to change it so that I can give it a string, like this:
String arg = "abcd";
callJNIMethod(arg);
在我的JNI代码中,这是以前的功能:
In my JNI code, this is what the function previously looked like:
JNIEXPORT jboolean JNICALL Java_com_file_app_Activity_callJNIMethod(
JNIEnv *env, jclass clazz){
//use the string
}
这就是我将其更改为的内容(在包装器.cpp文件和标头.h文件中):
This is what I changed it to (in the wrapper .cpp file and the header .h file):
JNIEXPORT jboolean JNICALL Java_com_file_app_Activity_callJNIMethod(
JNIEnv *env, jclass clazz, jstring str);
我收到一个错误消息,称方法callJNIMethod无法应用于给定类型.
I'm getting an error that the method callJNIMethod cannot be applied to the given types.
required: no arguments
found: java.lang.String
reason: actual and formal argument lists differ in length
Note: Some input files use or override a deprecated API.
有什么想法吗?
推荐答案
您通过编辑.h文件而误入歧途.对本机方法的更改应从您的Java源代码开始.
You went astray by editing the .h file. Changes to native methods should begin in your Java source.
.h文件应由javah
从编译的.class文件中生成.您可以将构建系统设置为在每个构建中重新运行javah
.这样,您将立即看到本机方法实现是否不再与Java源代码中的本机声明匹配.
The .h file should be generated by javah
from the compiled .class file. You can set up your build system to re-run javah
with each build. That way you'll see right away if the native method implementations no longer match the native declarations in your Java source.
这篇关于JNI方法:正式参数列表的长度不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!