Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JNI:使用“调用Java方法”;()签名_Java_Java Native Interface - Fatal编程技术网

JNI:使用“调用Java方法”;()签名

JNI:使用“调用Java方法”;()签名,java,java-native-interface,Java,Java Native Interface,有一个Java类带有getLong()和getCharArray()方法,我有指向这个类的jobject链接 此代码 jclass clsData = env->GetObjectClass(data); jmethodID getVal = env->GetMethodID(clsData, "getLong", "()J"); jlong x = env->CallLongMethod(data, getVal); 允许我访问getLong()返回的long值 如何访问字

有一个Java类带有
getLong()
getCharArray()
方法,我有指向这个类的jobject链接

此代码

jclass clsData = env->GetObjectClass(data);
jmethodID getVal = env->GetMethodID(clsData, "getLong", "()J");
jlong x = env->CallLongMethod(data, getVal);
允许我访问
getLong()
返回的long值


如何访问字符数组?

您可以通过这种方式获取字符数组这是另一篇文章的简单片段


您可以这样获得char数组这是另一篇文章的简单片段-完整的文章

jclass clsData = env->GetObjectClass(data);
jmethodID getVal = env->GetMethodID(clsData, "getCharArray", "()[C");
???
jobject obj = ... // This is the object you want to call the method on
jcharArray arr = (jcharArray) (*env)->CallObjectMethod(env, obj, getVal);
int count = (*env)->GetArrayLength(env, arr);
jchar* chars = (*env)->GetCharArrayElements(env, arr, 0);