Get<type>Field Routines - GetCharField
NativeType Get<type>Field
(JNIEnv *env, jobject obj,
jfieldID fieldID);
This family of accessor routines returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling
GetFieldID()
. (GetCharField)
The following table describes the Get<type>Field routine name and result type. You should replace type in Get<type>Field with the Java type of the field, or use one of the actual routine names from the table, and replace NativeType with the corresponding native type for that routine.
Table 4-1a Get<type>Field Family of Accessor Routines
LINKAGE:
Indices in the JNIEnv interface function table:
Table 4-1b Get<type>Field Family of Accessor Routines
PARAMETERS:
env
: the JNI interface pointer.obj
: a Java object (must not be NULL
).fieldID
: a valid field ID.RETURNS:
Returns the content of the field.
Example - GetCharField
static jboolean- getKeyData(JNIEnv *env, jobject clazz, jint ptr, jint keycode, jobject keydata)
- {
- jboolean rv;
- unsigned short displayLabel = env->GetCharField(keydata, gKeyDataDisplayLabelField);
- unsigned short number = env->GetCharField(keydata, gKeyDataNumberField);
- jcharArray chars = (jcharArray) env->GetObjectField(keydata, gKeyDataMetaField);
- jchar* ch = env->GetCharArrayElements(chars, NULL);
- KeyCharacterMap* kmap = reinterpret_cast<KeyCharacterMap*>(ptr);
- rv = kmap->getKeyData(keycode, &displayLabel, &number, ch);
- env->SetCharField(keydata, gKeyDataDisplayLabelField, displayLabel);
- env->SetCharField(keydata, gKeyDataNumberField, number);
- env->ReleaseCharArrayElements(chars, ch, 0);
- return rv;
- }