Call<type>Method Routines - CallVoidMethod
Call<type>MethodA Routines
Call<type>MethodV Routines
NativeType Call<type>Method
(JNIEnv *env, jobject obj, jmethodID methodID, ...);
NativeType Call<type>MethodA
(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
NativeType Call<type>MethodV
(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
Methods from these three families of operations are used to call a Java instance method from a native method.They only differ in their mechanism for passing parameters to the methods that they call.(CallVoidMethod)
These families of operations invoke an instance (nonstatic) method on a Java object, according to the specified method ID. The
methodID
argument must be obtained by calling GetMethodID
()
.
When these functions are used to call private methods and constructors, the method ID must be derived from the real class of
obj
, not from one of its superclasses. (CallVoidMethod)Call<type>Method Routines
Programmers place all arguments that are to be passed to the method immediately following the
methodID
argument. The Call<type>Method routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke.Call<type>MethodA Routines
Programmers place all arguments to the method in an
args
array of jvalues
that immediately follows the methodID
argument. The Call<type>MethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.Call<type>MethodV Routines
Programmers place all arguments to the method in an
args
argument of type va_list
that immediately follows the methodID
argument. The Call<type>MethodV 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 type. You should replace type in Call<type>Method with the Java type of the method you are calling (or use one of the actual method calling routine names from the table) and replace NativeType with the corresponding native type for that routine.
Table 4-3a Instance Method Calling Routines
LINKAGE:
Indices in the JNIEnv interface function table:
Table 4-3b Instance Method Calling Routines
PARAMETERS:
env
: the JNI interface pointer.obj
: a Java object.methodID
: a method ID.Additional Parameter for Call<type>Method Routines:
arguments to the Java method.
Additional Parameter for Call<type>MethodA Routines:
args
: an array of arguments.Additional Parameter for Call<type>MethodV Routines:
args
: a va_list of arguments.RETURNS:
Returns the result of calling the Java method.
THROWS:
Exceptions raised during the execution of the Java method.
Example -
CallVoidMethod
cls = (*env)->GetObjectClass(env, objID);
mid = (*env)->GetMethodID(env, cls, "setValue","(I)V");
if (0 == mid)
{
printf("GetMethodID returned 0\n");
return(-1);
}
(*env)->CallVoidMethod(env, objID, mid, cObjectID);