Sunday, April 21, 2013

jni jnienv SetStaticShortField example c c++ java


SetStatic<type>Field Routines - SetStaticShortField


void SetStatic<type>Field(JNIEnv *env, jclass clazz, jfieldID fieldID, NativeType value);

This family of accessor routines sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by callingGetStaticFieldID(). (SetStaticShortField)

The following table describes the set routine name and value types. You should replace type in SetStatic<type>Field with the Java type of the field, or one of the actual set static field routine names from the table, and replace NativeType with the corresponding native type for that routine.
Table 4-6a SetStatic<type>Field Family of Accessor Routines

SetStatic<type>Field Routine Name

NativeType

SetStaticObjectField()

jobject

SetStaticBooleanField()

jboolean

SetStaticByteField()

jbyte

SetStaticCharField()

jchar

SetStaticShortField()

jshort

SetStaticIntField()

jint

SetStaticLongField()

jlong

SetStaticFloatField()

jfloat

SetStaticDoubleField()

jdouble
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-6b SetStatic<type>Field Family of Accessor Routines
SetStatic<type>Field Routine Name
Index
SetStaticObjectField()
154
SetStaticBooleanField()
155
SetStaticByteField()
156
SetStaticCharField()
157
SetStaticShortField()
158
SetStaticIntField()
159
SetStaticLongField()
160
SetStaticFloatField()
161
SetStaticDoubleField()
162
PARAMETERS:

env: the JNI interface pointer.

clazz: a Java class object.

fieldID: a static field ID.

value: the new value of the field.
Example of SetStaticShortField


{

jfieldID jFieldId;
jshort iStaticShortVal;
jclass cls = (*env)->GetObjectClass(env, jobj);

jFieldId = (*env)->GetStaticFieldID(env,cls,"
iStaticShortVal","S");
if(jFieldId == 0) {
                printf("Field 
iStaticShortVal not Found in Hello class\n");
                return;
}
iStaticShortVal = (*env)->GetStaticShortField(env,cls,jFieldId);
(*env)->SetStaticShortField(env,cls,jFieldId,(
iStaticShortVal +2));  
}