CallStatic<type>Method Routines - CallStaticObjectMethod
CallStatic<type>MethodA Routines
CallStatic<type>MethodV Routines
NativeType CallStatic<type>Method
(JNIEnv *env, jclass clazz,
jmethodID methodID, ...);
NativeType CallStatic<type>MethodA
(JNIEnv *env, jclass clazz,
jmethodID methodID, jvalue *args);
NativeType CallStatic<type>MethodV
(JNIEnv *env, jclass clazz,
jmethodID methodID, va_list args);
(CallStaticObjectMethod)This family of operations invokes a static method on a Java object, according to the specified method ID. The
methodID
argument must be obtained by calling GetStaticMethodID
()
.
The method ID must be derived from
clazz
, not from one of its superclasses.
(CallStaticObjectMethod)
CallStatic<type>Method Routines
Programmers should place all arguments that are to be passed to the method immediately following the
methodID
argument. TheCallStatic<type>Method routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke. (CallStaticObjectMethod)CallStatic<type>MethodA Routines
Programmers should place all arguments to the method in an
args
array of jvalues
that immediately follows the methodID
argument. The CallStaticMethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.CallStatic<type>MethodV Routines
Programmers should place all arguments to the method in an
args
argument of type va_list
that immediately follows the methodID
argument. The CallStaticMethodV routine accepts the arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.
The following table describes each of the method calling routines according to their result types. You should replace type inCallStatic<type>Method with the Java type of the method, or one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
Table 4-7a CallStatic<type>Method Calling Routines
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-7b CallStatic<type>Method Calling Routines
PARAMETERS of CallStaticObjectMethod
env
: the JNI interface pointer.clazz
: a Java class object.methodID
: a static method ID.Additional Parameter for CallStatic<type>Method Routines:
arguments to the static method.
Additional Parameter for CallStatic<type>MethodA Routines:
args
: an array of arguments.Additional Parameter for CallStatic<type>MethodV Routines:
args
: a va_list
of arguments.RETURNS:
Returns the result of calling the static Java method.
THROWS:
Exceptions raised during the execution of the Java method.
Example of
CallStaticObjectMethodjmethodID method = env->GetStaticMethodID( cls, "getData", "()[Ljava/lang/String;" );
jarray data = (jarray) env->CallStaticObjectMethod( cls, method );
// assumption: the result of getData() is never null
jsize const length = env->GetArrayLength(data);
// assumption: the String[] is always of length > 0
char** args = new char*[ length ];
for( jsize index(0); index < length; ++index )
{
jstring element = (jstring) env->GetObjectArrayElement( array, index );
// assumption: there are no null strings in the array
char const* nativeString = env->GetStringUTFChars( element, 0 );
jsize const nativeLength = strlen(nativeString);
args[index] = new char[ nativeLength + 1 ];
strncpy( args[index], nativeString, nativeLength );
env->ReleaseStringUTFChars( element, nativeString );
}