can i call java method from native code?if so how?

*爱你&永不变心* 提交于 2020-01-14 03:37:11

问题


I have a Java function which can take variable number of parameters and in JNI I am receiving all the parameters in jobjectArray. But the problem is all the parameters available in String type,but originally thy are of different datatype. So in c/c++ converting them to their original type is not possible. So if i could call some other java method which will make these conversions easy for me.is it possible in to call a java method from native code in JNI?

Please help me out. I am really struck at it from a long time. Thanks in advance.


回答1:


Here's a succinct example: http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html.

Fundamentally you need to look up native objects representing the class and method you want to call, format your arguments, call the appropriate JNIEnv->CallXXX method, and process the resulting value.




回答2:


we can pass the String as a parameter from native code when you callback the java method using env->NewStringUTF(actual parameter).



来源:https://stackoverflow.com/questions/8624153/can-i-call-java-method-from-native-codeif-so-how

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