How do I specify in GetMethodID
function signature parameter that the function I am getting id for accepts array of a custom class?
I have one function in java with signature:
void getData( ListDataClass[] arryData )
And i want to get the method id of this function from the JNI interface using GetMethodID function.
For that i have mentioned in function signature parameter as following:
"([myPackeg/ListDataClass)V"
But this is not working and i get exception as Method Not Found
. Same thing works if i specify array of string class.
JNI type signatures for fully-qualified-classes take the form:
Lclass/path/ClassName;
For example:
"Ljava/lang/String;" // String
"[Ljava/lang/String;" // String[] (array)
A method signature is built up from these by placing arguments within parentheses first and the return type after the right bracket. For example:
long f (int n, String s, int[] arr); // Java method
"(ILjava/lang/String;[I)J" // JNI type signature
You can find the docs for for JNI type signatures here, which is where I borrowed the above example from.
In your specific example:
void getData( ListDataClass[] arryData ) // Java method
"([Lclass/path/ListDataClass;)V" // JNI type signature
Note: the exact type signature depends on your class path.
You can then find the method ID as follows (assuming C++ and a JNIEnv pointer called env):
jclass clz = env->FindClass("class/path/ListDataClass");
jmethodID mid = env->GetMethodID(clz, "getData", "([Lclass/path/ListDataClass;)V");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With