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?
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:
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;”.