GetFieldID
jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
Returns the field ID for an instance (nonstatic) field of a class. The field is specified by its name and signature. The Get<type>Field and Set<type>Field families of accessor functions use field IDs to retrieve object fields.
GetFieldID()
causes an uninitialized class to be initialized.GetFieldID()
cannot be used to obtain the length field of an array. Use GetArrayLength()
instead.LINKAGE:
Index 94 in the JNIEnv interface function table.
PARAMETERS of GetFieldID
env
: the JNI interface pointer.clazz
: a Java class object.name
: the field name in a 0-terminated modified UTF-8 string.sig
: the field signature in a 0-terminated modified UTF-8 string.RETURNS:
Returns a field ID, or
NULL
if the operation fails.THROWS:
NoSuchFieldError
: if the specified field cannot be found.ExceptionInInitializerError
: if the class initializer fails due to an exception.OutOfMemoryError
: if the system runs out of memory.
Example - GetFieldID
jclass c = (*env)->GetObjectClass(env, this); jfieldID fid = (*env)->GetFieldID(env, c, "private_variable", "I"); (*env)->SetIntField (env, this, fid, val);
jclass c = (*env)->GetObjectClass(env, this); jfieldID fid = (*env)->GetFieldID(env, c, "private_variable", "I"); jint val = (*env)->GetIntField(env, this, fid);