tags:

views:

27

answers:

2

When calling the GetFieldID method through the JNI environment variable, you are required to provide a Field Descriptor for the desired field. How do you find what the Field Descriptor for an object is?

Example:

jfieldID strField = env->GetFieldID(myClass, "example", "Ljava/lang/String;");

How would I determine that "Ljava/lang/String;" is the Field Descriptor for a String object?

+1  A: 

The JNI documentation describes how to translate a java type into a type string supported by JNI. You will need to know the type before you get at the fieldId.

Michael Barker
A: 

The javap tool will tell you what the Field Descriptor for a class is. To use it, navigate to a directory with a compiled .class file for the object with a field to be accessed and run the following command:

javap -s -p MyClass

This command will print out all of field descriptors for the class.

In general, however, most (non-primative) descriptors are of the form "Lfully/qualified/name/of/MyClass;".

TwentyMiles