Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify array of class in GetMethodID method signature parameter?

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.

like image 845
User7723337 Avatar asked Feb 24 '12 15:02

User7723337


1 Answers

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");
like image 195
GooseSerbus Avatar answered Sep 17 '22 20:09

GooseSerbus