Search code examples
cjava-native-interfacejnienv

How to call a String returning java method from C JNI?


There are many functions available for calling java from C, However there is no function for call String returning java methods. Can someone please advise how I can call string returning java method from C?

    CallBooleanMethod,
    CallBooleanMethodV,
    CallBooleanMethodA,
    CallByteMethod,
    CallByteMethodV,
    CallByteMethodA,
    CallCharMethod,
    CallCharMethodV,
    CallCharMethodA,
    CallShortMethod,
    CallShortMethodV,
    CallShortMethodA,
    CallIntMethod,
    CallIntMethodV,
    CallIntMethodA,
    CallLongMethod,
    CallLongMethodV,
    CallLongMethodA,
    CallFloatMethod,
    CallFloatMethodV,
    CallFloatMethodA,
    CallDoubleMethod,
    CallDoubleMethodV,
    CallDoubleMethodA,
    CallVoidMethod,
    CallVoidMethodV,
    CallVoidMethodA,

Solution

  • You can use CallObjectMethod() and friends. If the JAVA method returns String. then the jobject returned can be cast to jstring and you can use GetStringChars() to obtain a jchar *