JNI method: formal argument lists differ in length

谁说我不能喝 提交于 2020-01-17 03:42:08

问题


I'm trying to emend a JNI function that takes a string argument from the java layer.

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);

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
}

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);

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.

Any idea what's wrong?


回答1:


You went astray by editing the .h file. Changes to native methods should begin in your Java source.

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.



来源:https://stackoverflow.com/questions/31038813/jni-method-formal-argument-lists-differ-in-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!