Convert java code that returns object with template into c++ using jni

Nikolai Semenkov :

I need to call some java code from C++ using JNI.

I can't figure out how to get a value from a returned java generic with JNI. Java code that I need to call from C++ is:

encoderCapabilities.getQualityRange().getLower()

The problem is java returns the generic type Range<Integer>:

public Range<Integer> getQualityRange ()

I tried to use following C++ code, but it crash:

GetMethodID and CallObjectMethodV with function name getQualityRange and arguments ()Landroid/util/Range;. It seems did not crash, but next call crash:

getLower, ()I

Could you please suggest what code can work?

The object Range is fine as its method toString returns valid string "[1,100]", but "getLower" failed on getting methods. Upd: The Answer from Botje works!

Botje :

After type erasure, Range#getLower will have declared type Comparable, regardless of what the type in the Java source was.

Try this instead:

jobject range = ...;
jclass cls_Range = env->GetObjectClass(range);
jmethodID mid_Range_getLower = env->GetMethodID(cls_Range, "getLower", "()Ljava/lang/Comparable;");

jobject lower = env->CallObjectMethod(range, mid_Range_getLower);
jclass cls_Integer = env->GetObjectClass(lower);
jmethodID mid_Integer_intVale = env->GetMethodID(cls_Integer, "intValue", "()I");
jint lowerInt = env->CallIntMethod(lower, mid_Integer_intValue);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

JNI: From C code to Java and JNI

From Java

Can I reference C++ objects in Java Code using JNI?

From Java

Using a java socket from JNI / C++ code

From Dev

When using JNI to port in existing C++ code, use C or C++ to interface with JAVA?

From Dev

Return Scala object to C++ using JNI

From Java

Rewrite C code in Java or use JNI?

From Java

How to send Java ByteBuffer to C using JNI?

From Dev

How to convert the contents of a Java byte array to C string in JNI?

From Java

How to Use Eclipse to Debug JNI code (Java & C/C++)

From Dev

How do I instantiate a java object using JNI (Delphi)

From Dev

JNI Java using DLL function which takes an object as param

From Dev

Keeping a native object in memory between calls from Java using JNI

From Dev

Calling a Java Method from the native code using jni

From Java

How to pass C structs back and forth to Java code in JNI?

From Dev

How to debug native jni c++ code in eclipse with java project

From Dev

Return a string from JNI (C++) code to Java

From Dev

How to use JNI_GetCreatedJavaVMs in C++ to call Java Code

From Dev

Convert java code to Objective c

From Dev

objective-c code convert for java code

From Dev

how to convert a JSON API returns an object to an array for using .map()

From Dev

Using C code in Python returns strange values

From Dev

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

From Java

Passing strings from java to c++ using JNI

From Java

How to obtain a description of a Java exception in C++ when using JNI?

From Java

Copying Data from Java to C++ Objects Array Using JNI

From Dev

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

From Dev

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

From Dev

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

From Dev

How to pass a Java Integer array into C using JNI?

Related Related

  1. 1

    JNI: From C code to Java and JNI

  2. 2

    Can I reference C++ objects in Java Code using JNI?

  3. 3

    Using a java socket from JNI / C++ code

  4. 4

    When using JNI to port in existing C++ code, use C or C++ to interface with JAVA?

  5. 5

    Return Scala object to C++ using JNI

  6. 6

    Rewrite C code in Java or use JNI?

  7. 7

    How to send Java ByteBuffer to C using JNI?

  8. 8

    How to convert the contents of a Java byte array to C string in JNI?

  9. 9

    How to Use Eclipse to Debug JNI code (Java & C/C++)

  10. 10

    How do I instantiate a java object using JNI (Delphi)

  11. 11

    JNI Java using DLL function which takes an object as param

  12. 12

    Keeping a native object in memory between calls from Java using JNI

  13. 13

    Calling a Java Method from the native code using jni

  14. 14

    How to pass C structs back and forth to Java code in JNI?

  15. 15

    How to debug native jni c++ code in eclipse with java project

  16. 16

    Return a string from JNI (C++) code to Java

  17. 17

    How to use JNI_GetCreatedJavaVMs in C++ to call Java Code

  18. 18

    Convert java code to Objective c

  19. 19

    objective-c code convert for java code

  20. 20

    how to convert a JSON API returns an object to an array for using .map()

  21. 21

    Using C code in Python returns strange values

  22. 22

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

  23. 23

    Passing strings from java to c++ using JNI

  24. 24

    How to obtain a description of a Java exception in C++ when using JNI?

  25. 25

    Copying Data from Java to C++ Objects Array Using JNI

  26. 26

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

  27. 27

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

  28. 28

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

  29. 29

    How to pass a Java Integer array into C using JNI?

HotTag

Archive