Accessing field using JNI

user1759789

I have a java class that has two fields - one is a private final double and the other is a private Map; I have added a public getter method for the Map. I am accessing them from my C code using JNI. I am having problems getting the Map via the field but have no problem getting it through the method:

    // The following lines of code work just fine
    jclass jCls = (*env)->GetObjectClass(env,object);
    jfieldID dblFldId = (*env)->GetFieldID(env,jCls,"nameOfDoubleVariable","D");
    jdouble dblVar = (*env)->GetDoubleField(env, object, dblFldId);

    // These lines don't work though
    jfieldID mapId = (*env)->GetFieldID(env,jCls,"nameOfMapVariable","()Ljava/util/Map;");
    jobject mapVar = (*env)->GetObjectField(env,object,mapId);

But if I replace the two lines that don't work with the following (essentially I am getting the map via the method instead of directly via the field) it does work:

    jmethodID m_GetMap = (*env)->GetMethodID(env,jCls,"getMap","()Ljava/util/Map;");
    jobject mapVar = (*env)->CallObjectMethod(env,object,m_GetMap);

Can anyone tell me why the method call works but not getting it from the field - I am sure I am doing something wrong!

István Pecznyik

The error is that you try to get a field with a function signature. Try with this:

jfieldID mapId = (*env)->GetFieldID(env,jCls,"nameOfMapVariable","Ljava/util/Map;");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Accessing a class field using a string

From Dev

Accessing a random field using other field value

From Dev

accessing value of input field by id using jquery

From Java

Error accessing field (using Hibernate/JPA)

From

Accessing a specific field using Type Embedding?

From Dev

Accessing a struct field using an int or enum value

From Dev

Scala: accessing properties using covariant Field[+T]

From Dev

Accessing objects field using string in Typescript

From Dev

Error accessing field : using @OneToMany Annotation in Hibernate

From Dev

Accessing azure custom field using OData query

From Dev

Accessing private field of TextView in Android 11 using Kotlin 1.5.20?

From Dev

Accessing 'checked' state for checkbox using Angular field binding

From Dev

Accessing Field Settings of Pivot Table using Apache POI

From Dev

Chaining an element using css containing text and accessing an associated field

From Dev

when accessing an object field using get method,value always undefined

From Dev

Accessing ViewModel field in SwiftUI using Xcode 12: "Accessing State's value outside of being installed on a View"

From Java

Accessing field of outer class

From Java

PropertyAccessException: Error accessing field

From Dev

KeyError accessing field in JSON

From Dev

Accessing field of an object

From Dev

Accessing a field in csh

From Java

JNI modify a static field of java

From Java

Using GetDirectBufferAddress from JNI

From Java

Using JNI to load another JNI library?

From Dev

Accessing parent class static field using child class name doesn't load the child class?

From Dev

Accessing a m2m field values in django templates using forms

From Dev

Is accessing a Lua table field faster then accessing a cdata field?

From Dev

Accessing variable field/column in a raw

From Dev

RForcecom accessing unknown field names

Related Related

  1. 1

    Accessing a class field using a string

  2. 2

    Accessing a random field using other field value

  3. 3

    accessing value of input field by id using jquery

  4. 4

    Error accessing field (using Hibernate/JPA)

  5. 5

    Accessing a specific field using Type Embedding?

  6. 6

    Accessing a struct field using an int or enum value

  7. 7

    Scala: accessing properties using covariant Field[+T]

  8. 8

    Accessing objects field using string in Typescript

  9. 9

    Error accessing field : using @OneToMany Annotation in Hibernate

  10. 10

    Accessing azure custom field using OData query

  11. 11

    Accessing private field of TextView in Android 11 using Kotlin 1.5.20?

  12. 12

    Accessing 'checked' state for checkbox using Angular field binding

  13. 13

    Accessing Field Settings of Pivot Table using Apache POI

  14. 14

    Chaining an element using css containing text and accessing an associated field

  15. 15

    when accessing an object field using get method,value always undefined

  16. 16

    Accessing ViewModel field in SwiftUI using Xcode 12: "Accessing State's value outside of being installed on a View"

  17. 17

    Accessing field of outer class

  18. 18

    PropertyAccessException: Error accessing field

  19. 19

    KeyError accessing field in JSON

  20. 20

    Accessing field of an object

  21. 21

    Accessing a field in csh

  22. 22

    JNI modify a static field of java

  23. 23

    Using GetDirectBufferAddress from JNI

  24. 24

    Using JNI to load another JNI library?

  25. 25

    Accessing parent class static field using child class name doesn't load the child class?

  26. 26

    Accessing a m2m field values in django templates using forms

  27. 27

    Is accessing a Lua table field faster then accessing a cdata field?

  28. 28

    Accessing variable field/column in a raw

  29. 29

    RForcecom accessing unknown field names

HotTag

Archive