I have the following native method in Java :
public class ConsoleIO
{
public native static void printList(List<String> list);
......
}
and the corresponding C implementation with JNI is the following :
JNIEXPORT void JNICALL Java_ConsoleIO_printList(JNIEnv *env, jclass cls, jobject obj)
{
}
Now I need to pass a list of Strings from java to the printList(List list) method and loop through it from the above C implementation and print them in the console from the C function.
I know that there is no C representation of this List type, but I need to know that how I can do access this List of strings in C and print them out in C itself?
Thanks in advance!
I found the solution for this :
JNIEXPORT void JNICALL Java_ConsoleIO_printList(JNIEnv *env, jclass cls, jobject obj)
{
jclass listClass = (*env)->GetObjectClass(env,obj);
jmethodID sizeMethod = (*env)->(env,listClass,"size","()I");
jmethodID getMethod = (*env)->GetMethodID(env,listClass,"get","(I)Ljava/lang/Object");
jint size = (*env)->CallIntMethod(env,sizeMethod);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments