Passing Java ArryList<String> to JNI C function and print the list in C

Dileepa Rajapaksa :

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!

Dileepa Rajapaksa :

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Passing pointers between C and Java through JNI

From Java

Send C++ string to Java via JNI

From Java

passing string array from java to C with JNI

From Java

Problem passing byte[] via jni to C on Android

From Java

How to pass List from Java to JNI C++ as vector by ref?

From Java

JNI: passing integer array from Java to C

From Java

Passing strings from java to c++ using JNI

From Dev

Passing a list of string as an argument to javascript function from native java code

From Dev

Call a function in java from C outside of a JNI function (Android)?

From Dev

C - Passing a pointer to an array to a function to print the array

From Dev

Passing a list/arraylist of reference type objects contained in a class to JNI/C++

From Dev

Passing float[] from C++ to Java using JNI

From Dev

C++: Passing a linked list to a static function

From Dev

Passing string into function and modifying in C (trouble with pointers)

From Dev

How to call a function with arguments in C++ from JAVA using JNI?

From Dev

Return list<unsigned char*> from C++ to Java using JNI

From Dev

Passing a pointer (string) to a C function

From Dev

c++ Passing List Of Classes In Function Parameter

From Dev

JNI How to concatenate two string arrays in C++ native function

From Dev

Binding a C++ class member function to Java using JNI

From Dev

C passing string to function issue

From Dev

Passing swift string to c function char *

From Dev

C passing a linked list struct to a function

From Dev

Passing input string to a function in C

From Dev

Calling a Java variadic function from C through the JNI

From Dev

Passing a linked list as an argument to a function in C

From Dev

Passing a String as a Function in a Linked List in C

From Dev

For inside Arrylist's map function in Java

From Dev

Passing c-style string to a template function

Related Related

  1. 1

    Passing pointers between C and Java through JNI

  2. 2

    Send C++ string to Java via JNI

  3. 3

    passing string array from java to C with JNI

  4. 4

    Problem passing byte[] via jni to C on Android

  5. 5

    How to pass List from Java to JNI C++ as vector by ref?

  6. 6

    JNI: passing integer array from Java to C

  7. 7

    Passing strings from java to c++ using JNI

  8. 8

    Passing a list of string as an argument to javascript function from native java code

  9. 9

    Call a function in java from C outside of a JNI function (Android)?

  10. 10

    C - Passing a pointer to an array to a function to print the array

  11. 11

    Passing a list/arraylist of reference type objects contained in a class to JNI/C++

  12. 12

    Passing float[] from C++ to Java using JNI

  13. 13

    C++: Passing a linked list to a static function

  14. 14

    Passing string into function and modifying in C (trouble with pointers)

  15. 15

    How to call a function with arguments in C++ from JAVA using JNI?

  16. 16

    Return list<unsigned char*> from C++ to Java using JNI

  17. 17

    Passing a pointer (string) to a C function

  18. 18

    c++ Passing List Of Classes In Function Parameter

  19. 19

    JNI How to concatenate two string arrays in C++ native function

  20. 20

    Binding a C++ class member function to Java using JNI

  21. 21

    C passing string to function issue

  22. 22

    Passing swift string to c function char *

  23. 23

    C passing a linked list struct to a function

  24. 24

    Passing input string to a function in C

  25. 25

    Calling a Java variadic function from C through the JNI

  26. 26

    Passing a linked list as an argument to a function in C

  27. 27

    Passing a String as a Function in a Linked List in C

  28. 28

    For inside Arrylist's map function in Java

  29. 29

    Passing c-style string to a template function

HotTag

Archive