Java jni check exception



Chapter 4: JNI Functions

This chapter serves as the reference section for the JNI functions. It provides a complete listing of all the JNI functions. It also presents the exact layout of the JNI function table.

Note the use of the term “must” to describe restrictions on JNI programmers. For example, when you see that a certain JNI function must receive a non-NULL object, it is your responsibility to ensure that NULL is not passed to that JNI function. As a result, a JNI implementation does not need to perform NULL pointer checks in that JNI function.

A portion of this chapter is adapted from Netscape’s JRI documentation.

The reference material groups functions by their usage. The reference section is organized by the following functional areas:

Interface Function Table

Each function is accessible at a fixed offset through the JNIEnv argument. The JNIEnv type is a pointer to a structure storing all JNI function pointers. It is defined as follows:

The VM initializes the function table, as shown by the following code example. Note that the first three entries are reserved for future compatibility with COM. In addition, we reserve a number of additional NULL entries near the beginning of the function table, so that, for example, a future class-related JNI operation can be added after FindClass, rather than at the end of the table.

Note that the function table can be shared among all JNI interface pointers.

Version Information

GetVersion

jint GetVersion(JNIEnv *env);

Returns the version of the native method interface.

LINKAGE:

Index 4 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

RETURNS:

Returns the major version number in the higher 16 bits and the minor version number in the lower 16 bits.

In JDK/JRE 1.1, GetVersion() returns 0x00010001 .

In JDK/JRE 1.2, GetVersion() returns 0x00010002 .

In JDK/JRE 1.4, GetVersion() returns 0x00010004 .

In JDK/JRE 1.6, GetVersion() returns 0x00010006 .

Constants

SINCE JDK/JRE 1.2:

SINCE JDK/JRE 1.4:

SINCE JDK/JRE 1.6:

Class Operations

DefineClass

jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
const jbyte *buf, jsize bufLen);

Loads a class from a buffer of raw class data. The buffer containing the raw class data is not referenced by the VM after the DefineClass call returns, and it may be discarded if desired.

LINKAGE:

Index 5 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

name : the name of the class or interface to be defined. The string is encoded in modified UTF-8.

loader : a class loader assigned to the defined class.

buf : buffer containing the .class file data.

bufLen : buffer length.

RETURNS:

Returns a Java class object or NULL if an error occurs.

THROWS:

ClassFormatError : if the class data does not specify a valid class.

ClassCircularityError : if a class or interface would be its own superclass or superinterface.

OutOfMemoryError : if the system runs out of memory.

SecurityException : if the caller attempts to define a class in the «java» package tree.

FindClass

jclass FindClass(JNIEnv *env, const char *name);

In JDK release 1.1, this function loads a locally-defined class. It searches the directories and zip files specified by the CLASSPATH environment variable for the class with the specified name.

Since Java 2 SDK release 1.2, the Java security model allows non-system classes to load and call native methods. FindClass locates the class loader associated with the current native method; that is, the class loader of the class that declared the native method. If the native method belongs to a system class, no class loader will be involved. Otherwise, the proper class loader will be invoked to load and link the named class.

Since Java 2 SDK release 1.2, when FindClass is called through the Invocation Interface, there is no current native method or its associated class loader. In that case, the result of ClassLoader.getSystemClassLoader is used. This is the class loader the virtual machine creates for applications, and is able to locate classes listed in the java.class.path property.

The name argument is a fully-qualified class name or an array type signature . For example, the fully-qualified class name for the java.lang.String class is:

The array type signature of the array class java.lang.Object[] is:

LINKAGE:

Index 6 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

name : a fully-qualified class name (that is, a package name, delimited by “ / ”, followed by the class name). If the name begins with “ [ “ (the array signature character), it returns an array class. The string is encoded in modified UTF-8.

RETURNS:

Returns a class object from a fully-qualified name, or NULL if the class cannot be found.

THROWS:

ClassFormatError : if the class data does not specify a valid class.

ClassCircularityError : if a class or interface would be its own superclass or superinterface.

NoClassDefFoundError : if no definition for a requested class or interface can be found.

OutOfMemoryError : if the system runs out of memory.

GetSuperclass

jclass GetSuperclass(JNIEnv *env, jclass clazz);

If clazz represents any class other than the class Object , then this function returns the object that represents the superclass of the class specified by clazz .

If clazz specifies the class Object , or clazz represents an interface, this function returns NULL .

LINKAGE:

Index 10 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

clazz : a Java class object.

RETURNS:

Returns the superclass of the class represented by clazz , or NULL .

IsAssignableFrom

jboolean IsAssignableFrom(JNIEnv *env, jclass clazz1,
jclass clazz2);

Determines whether an object of clazz1 can be safely cast to clazz2 .

LINKAGE:

Index 11 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

clazz1 : the first class argument.

clazz2 : the second class argument.

RETURNS:

Returns JNI_TRUE if either of the following is true:

  • The first and second class arguments refer to the same Java class.
  • The first class is a subclass of the second class.
  • The first class has the second class as one of its interfaces.

Exceptions

Throw

jint Throw(JNIEnv *env, jthrowable obj);

Causes a java.lang.Throwable object to be thrown.

LINKAGE:

Index 13 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

obj : a java.lang.Throwable object.

RETURNS:

Returns 0 on success; a negative value on failure.

THROWS:

the java.lang.Throwable object obj .

ThrowNew

jint ThrowNew(JNIEnv *env, jclass clazz,
const char *message);

Constructs an exception object from the specified class with the message specified by message and causes that exception to be thrown.

LINKAGE:

Index 14 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

clazz : a subclass of java.lang.Throwable .

message : the message used to construct the java.lang.Throwable object. The string is encoded in modified UTF-8.

RETURNS:

Returns 0 on success; a negative value on failure.

THROWS:

the newly constructed java.lang.Throwable object.

ExceptionOccurred

jthrowable ExceptionOccurred(JNIEnv *env);

Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear() , or the Java code handles the exception.

LINKAGE:

Index 15 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

RETURNS:

Returns the exception object that is currently in the process of being thrown, or NULL if no exception is currently being thrown.

ExceptionDescribe

void ExceptionDescribe(JNIEnv *env);

Prints an exception and a backtrace of the stack to a system error-reporting channel, such as stderr . This is a convenience routine provided for debugging.

LINKAGE:

Index 16 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

Читайте также:  Kernel32 dll error fix

ExceptionClear

void ExceptionClear(JNIEnv *env);

Clears any exception that is currently being thrown. If no exception is currently being thrown, this routine has no effect.

LINKAGE:

Index 17 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

FatalError

void FatalError(JNIEnv *env, const char *msg);

Raises a fatal error and does not expect the VM to recover. This function does not return.

LINKAGE:

Index 18 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

msg : an error message. The string is encoded in modified UTF-8.

ExceptionCheck

jboolean ExceptionCheck(JNIEnv *env);

Returns JNI_TRUE when there is a pending exception; otherwise, returns JNI_FALSE .

LINKAGE:

SINCE:

Global and Local References

Global References

NewGlobalRef

jobject NewGlobalRef(JNIEnv *env, jobject obj);

Creates a new global reference to the object referred to by the obj argument. The obj argument may be a global or local reference. Global references must be explicitly disposed of by calling DeleteGlobalRef() .

LINKAGE:

Index 21 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

obj : a global or local reference.

RETURNS:

Returns a global reference to the given obj .

May return NULL if:

  • obj refers to null
  • the system has run out of memory
  • obj was a weak global reference and has already been garbage collected

DeleteGlobalRef

void DeleteGlobalRef(JNIEnv *env, jobject globalRef);

Deletes the global reference pointed to by globalRef .

LINKAGE:

Index 22 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

globalRef : a global reference.

Local References

Local references are valid for the duration of a native method call. They are freed automatically after the native method returns. Each local reference costs some amount of Java Virtual Machine resource. Programmers need to make sure that native methods do not excessively allocate local references. Although local references are automatically freed after the native method returns to Java, excessive allocation of local references may cause the VM to run out of memory during the execution of a native method.

DeleteLocalRef

void DeleteLocalRef(JNIEnv *env, jobject localRef);

Deletes the local reference pointed to by localRef .

LINKAGE:

Index 23 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

localRef : a local reference.

Note: JDK/JRE 1.1 provides the DeleteLocalRef function above so that programmers can manually delete local references. For example, if native code iterates through a potentially large array of objects and uses one element in each iteration, it is a good practice to delete the local reference to the no-longer-used array element before a new local reference is created in the next iteration.

As of JDK/JRE 1.2 an additional set of functions are provided for local reference lifetime management. They are the four functions listed below.

EnsureLocalCapacity

jint EnsureLocalCapacity(JNIEnv *env, jint capacity);

Ensures that at least a given number of local references can be created in the current thread. Returns 0 on success; otherwise returns a negative number and throws an OutOfMemoryError .

Before it enters a native method, the VM automatically ensures that at least 16 local references can be created.

For backward compatibility, the VM allocates local references beyond the ensured capacity. (As a debugging support, the VM may give the user warnings that too many local references are being created. In the JDK, the programmer can supply the -verbose:jni command line option to turn on these messages.) The VM calls FatalError if no more local references can be created beyond the ensured capacity.

LINKAGE:

SINCE:

PushLocalFrame

jint PushLocalFrame(JNIEnv *env, jint capacity);

Creates a new local reference frame, in which at least a given number of local references can be created. Returns 0 on success, a negative number and a pending OutOfMemoryError on failure.

Note that local references already created in previous local frames are still valid in the current local frame.

LINKAGE:

SINCE:

PopLocalFrame

jobject PopLocalFrame(JNIEnv *env, jobject result);

Pops off the current local reference frame, frees all the local references, and returns a local reference in the previous local reference frame for the given result object.

Pass NULL as result if you do not need to return a reference to the previous frame.

LINKAGE:

SINCE:

NewLocalRef

jobject NewLocalRef(JNIEnv *env, jobject ref);

Creates a new local reference that refers to the same object as ref . The given ref may be a global or local reference. Returns NULL if ref refers to null .

LINKAGE:

SINCE:

Weak Global References

Weak global references are a special kind of global reference. Unlike normal global references, a weak global reference allows the underlying Java object to be garbage collected. Weak global references may be used in any situation where global or local references are used.

Weak global references are related to Java phantom references ( java.lang.ref.PhantomReference ). A weak global reference to a specific object is treated as a phantom reference referring to that object when determining whether the object is phantom reachable (see java.lang.ref ). Such a weak global reference will become functionally equivalent to NULL at the same time as a PhantomReference referring to that same object would be cleared by the garbage collector.

Since garbage collection may occur while native methods are running, objects referred to by weak global references can be freed at any time. While weak global references can be used where global references are used, it is generally inappropriate to do so, as they may become functionally equivalent to NULL without notice.

IsSameObject can be used to compare a weak global reference to a non- NULL local or global reference. If the objects are the same, the weak global reference won’t become functionally equivalent to NULL so long as the other reference has not been deleted.

IsSameObject can also be used to compare a weak global reference to NULL to determine whether the underlying object has been freed. However, programmers should not rely on this check to determine whether a weak global reference may be used (as a non- NULL reference) in any future JNI function call, since an intervening garbage collection could change the weak global reference.

Instead, it is recommended that a (strong) local or global reference to the underlying object be acquired using one of the JNI functions NewLocalRef or NewGlobalRef . These functions will return NULL if the object has been freed. Otherwise, the new reference will prevent the underlying object from being freed. The new reference, if non- NULL , can then be used to access the underlying object, and deleted when such access is no longer needed.

NewWeakGlobalRef

jweak NewWeakGlobalRef(JNIEnv *env, jobject obj);

Creates a new weak global reference. Returns NULL if obj refers to null , or if the VM runs out of memory. If the VM runs out of memory, an OutOfMemoryError will be thrown.

LINKAGE:

SINCE:

DeleteWeakGlobalRef

void DeleteWeakGlobalRef(JNIEnv *env, jweak obj);

Delete the VM resources needed for the given weak global reference.

LINKAGE:

SINCE:

Object Operations

AllocObject

jobject AllocObject(JNIEnv *env, jclass clazz);

Allocates a new Java object without invoking any of the constructors for the object. Returns a reference to the object.

The clazz argument must not refer to an array class.

LINKAGE:

Index 27 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

clazz : a Java class object.

RETURNS:

Returns a Java object, or NULL if the object cannot be constructed.

THROWS:

InstantiationException : if the class is an interface or an abstract class.

OutOfMemoryError : if the system runs out of memory.

Читайте также:  Sql error no sql cursors

NewObject, NewObjectA, NewObjectV

jobject NewObject(JNIEnv *env, jclass clazz,
jmethodID methodID, . );

jobject NewObjectA(JNIEnv *env, jclass clazz,
jmethodID methodID, const jvalue *args);

jobject NewObjectV(JNIEnv *env, jclass clazz,
jmethodID methodID, va_list args);

Constructs a new Java object. The method ID indicates which constructor method to invoke. This ID must be obtained by calling GetMethodID() with as the method name and void ( V ) as the return type.

The clazz argument must not refer to an array class.

NewObject

Programmers place all arguments that are to be passed to the constructor immediately following the methodID argument. NewObject() accepts these arguments and passes them to the Java method that the programmer wishes to invoke.

LINKAGE:

Index 28 in the JNIEnv interface function table.

NewObjectA

Programmers place all arguments that are to be passed to the constructor in an args array of jvalues that immediately follows the methodID argument. NewObjectA() accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.

LINKAGE:

Index 30 in the JNIEnv interface function table.

NewObjectV

Programmers place all arguments that are to be passed to the constructor in an args argument of type va_list that immediately follows the methodID argument. NewObjectV() accepts these arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.

LINKAGE:

Index 29 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

clazz : a Java class object.

methodID : the method ID of the constructor.

Additional Parameter for NewObject:

arguments to the constructor.

Additional Parameter for NewObjectA:

args : an array of arguments to the constructor.

Additional Parameter for NewObjectV:

args : a va_list of arguments to the constructor.

RETURNS:

Returns a Java object, or NULL if the object cannot be constructed.

THROWS:

InstantiationException : if the class is an interface or an abstract class.

OutOfMemoryError : if the system runs out of memory.

Any exceptions thrown by the constructor.

GetObjectClass

jclass GetObjectClass(JNIEnv *env, jobject obj);

Returns the class of an object.

LINKAGE:

Index 31 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

obj : a Java object (must not be NULL ).

RETURNS:

Returns a Java class object.

GetObjectRefType

jobjectRefType GetObjectRefType(JNIEnv* env, jobject obj);

Returns the type of the object referred to by the obj argument. The argument obj can either be a local, global or weak global reference.

LINKAGE:

Index 232 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

obj : a local, global or weak global reference.

vm : the virtual machine instance from which the interface will be retrieved.

env : pointer to the location where the JNI interface pointer for the current thread will be placed.

version : the requested JNI version.

RETURNS:

The function GetObjectRefType returns one of the following enumerated values defined as a jobjectRefType :

JNIInvalidRefType = 0,
JNILocalRefType = 1,
JNIGlobalRefType = 2,
JNIWeakGlobalRefType = 3

If the argument obj is a weak global reference type, the return will be JNIWeakGlobalRefType .

If the argument obj is a global reference type, the return value will be JNIGlobalRefType .

If the argument obj is a local reference type, the return will be JNILocalRefType .

If the obj argument is not a valid reference, the return value for this function will be JNIInvalidRefType .

An invalid reference is a reference which is not a valid handle. That is, the obj pointer address does not point to a location in memory which has been allocated from one of the Ref creation functions or returned from a JNI function.

As such, NULL would be an invalid reference and GetObjectRefType(env,NULL) would return JNIInvalidRefType .

On the other hand, a null reference, which is a reference that points to a null, would return the type of reference that the null reference was originally created as.

GetObjectRefType cannot be used on deleted references.

Since references are typically implemented as pointers to memory data structures that can potentially be reused by any of the reference allocation services in the VM, once deleted, it is not specified what value the GetObjectRefType will return.

SINCE:

IsInstanceOf

jboolean IsInstanceOf(JNIEnv *env, jobject obj,
jclass clazz);

Tests whether an object is an instance of a class.

LINKAGE:

Index 32 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

obj : a Java object.

clazz : a Java class object.

RETURNS:

Returns JNI_TRUE if obj can be cast to clazz ; otherwise, returns JNI_FALSE . A NULL object can be cast to any class.

IsSameObject

jboolean IsSameObject(JNIEnv *env, jobject ref1,
jobject ref2);

Tests whether two references refer to the same Java object.

LINKAGE:

Index 24 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

ref1 : a Java object.

ref2 : a Java object.

RETURNS:

Returns JNI_TRUE if ref1 and ref2 refer to the same Java object, or are both NULL ; otherwise, returns JNI_FALSE .

Accessing Fields of Objects

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 Field and Set 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:

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.

Get Field Routines

NativeType Get 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() .

The following table describes the Get Field routine name and result type. You should replace type in Get 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.

GetObjectField()
jobject
GetBooleanField() jboolean
GetByteField() jbyte
GetCharField() jchar
GetShortField() jshort
GetIntField() jint
GetLongField() jlong
GetFloatField() jfloat
GetDoubleField() jdouble

LINKAGE:

Indices in the JNIEnv interface function table:

GetObjectField()
95
GetBooleanField() 96
GetByteField() 97
GetCharField() 98
GetShortField() 99
GetIntField() 100
GetLongField() 101
GetFloatField() 102
GetDoubleField() 103

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.

Set Field Routines

void Set Field (JNIEnv *env, jobject obj, jfieldID fieldID,
NativeType value);

This family of accessor routines sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling GetFieldID() .

The following table describes the Set Field routine name and value type. You should replace type in Set 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.

Читайте также:  Error in parsing stream

SetObjectField()
jobject
S etBooleanField() jboolean
SetByteField() jbyte
SetCharField() jchar
SetShortField() jshort
SetIntField() jint
SetLongField() jlong
SetFloatField() jfloat
SetDoubleField() jdouble

LINKAGE:

Indices in the JNIEnv interface function table.

SetObjectField()
104
S etBooleanField() 105
SetByteField() 106
SetCharField() 107
SetShortField() 108
SetIntField() 109
SetLongField() 110
SetFloatField() 111
SetDoubleField() 112

PARAMETERS:

env : the JNI interface pointer.

obj : a Java object (must not be NULL ).

fieldID : a valid field ID.

value : the new value of the field.

Calling Instance Methods

GetMethodID

jmethodID GetMethodID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);

Returns the method ID for an instance (nonstatic) method of a class or interface. The method may be defined in one of the clazz ’s superclasses and inherited by clazz . The method is determined by its name and signature.

GetMethodID() causes an uninitialized class to be initialized.

To obtain the method ID of a constructor, supply as the method name and void ( V ) as the return type.

LINKAGE:

Index 33 in the JNIEnv interface function table.

PARAMETERS:

env : the JNI interface pointer.

clazz : a Java class object.

name : the method name in a 0-terminated modified UTF-8 string.

sig : the method signature in 0-terminated modified UTF-8 string.

RETURNS:

Returns a method ID, or NULL if the specified method cannot be found.

THROWS:

NoSuchMethodError : if the specified method cannot be found.

ExceptionInInitializerError : if the class initializer fails due to an exception.

OutOfMemoryError : if the system runs out of memory.

Call Method Routines, Call MethodA Routines, Call MethodV Routines

NativeType Call Method (JNIEnv *env, jobject obj,
jmethodID methodID, . );

NativeType Call MethodA (JNIEnv *env, jobject obj,
jmethodID methodID, const jvalue *args);

NativeType Call 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.

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.

Call Method Routines

Programmers place all arguments that are to be passed to the method immediately following the methodID argument. The Call Method routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke.

Call MethodA Routines

Programmers place all arguments to the method in an args array of jvalues that immediately follows the methodID argument. The Call MethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.

Call 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 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 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.

Instance Method Calling Routines

Call Method Routine Name Native Type
CallVoidMethod() CallVoidMethodA() CallVoidMethodV() void
CallObjectMethod() CallObjectMethodA() CallObjectMethodV() jobject
CallBooleanMethod() CallBooleanMethodA() CallBooleanMethodV() jboolean
CallByteMethod() CallByteMethodA() CallByteMethodV() jbyte
CallCharMethod() CallCharMethodA() CallCharMethodV() jchar
CallShortMethod() CallShortMethodA() CallShortMethodV() jshort
CallIntMethod() CallIntMethodA() CallIntMethodV() jint
CallLongMethod() CallLongMethodA() CallLongMethodV() jlong
CallFloatMethod() CallFloatMethodA() CallFloatMethodV() jfloat
CallDoubleMethod() CallDoubleMethodA() CallDoubleMethodV() jdouble

LINKAGE:

Indices in the JNIEnv interface function table:

Instance Method Calling Routines

PARAMETERS:

env : the JNI interface pointer.

obj : a Java object.

methodID : a method ID.

Additional Parameter for Call Method Routines:

arguments to the Java method.

Additional Parameter for Call MethodA Routines:

args : an array of arguments.

Additional Parameter for Call 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.

CallNonvirtual Method Routines, CallNonvirtual MethodA Routines, CallNonvirtual MethodV Routines

NativeType CallNonvirtual Method (JNIEnv *env, jobject obj,
jclass clazz, jmethodID methodID, . );

NativeType CallNonvirtual MethodA (JNIEnv *env, jobject obj,
jclass clazz, jmethodID methodID, const jvalue *args);

NativeType CallNonvirtual MethodV (JNIEnv *env, jobject obj,
jclass clazz, jmethodID methodID, va_list args);

These families of operations invoke an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodID argument must be obtained by calling GetMethodID () on the class clazz .

The CallNonvirtual Method families of routines and the Call Method families of routines are different. Call Method routines invoke the method based on the class of the object, while CallNonvirtual Method routines invoke the method based on the class, designated by the clazz parameter, from which the method ID is obtained. The method ID must be obtained from the real class of the object or from one of its superclasses.

CallNonvirtual Method Routines

Programmers place all arguments that are to be passed to the method immediately following the methodID argument. The CallNonvirtual Method routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke.

CallNonvirtual MethodA Routines

Programmers place all arguments to the method in an args array of jvalues that immediately follows the methodID argument. The CallNonvirtual MethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.

CallNonvirtual MethodV Routines

Programmers place all arguments to the method in an args argument of type va_list that immediately follows the methodID argument. The CallNonvirtualMethodV 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 CallNonvirtual Method with the Java type of the method, or use one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.

Call Method Routine Name Index
CallVoidMethod() CallVoidMethodA() CallVoidMethodV()
CallObjectMethod() CallObjectMethodA() CallObjectMethodV()
CallBooleanMethod() CallBooleanMethodA() CallBooleanMethodV()
CallByteMethod() CallByteMethodA() CallByteMethodV()
CallCharMethod() CallCharMethodA() CallCharMethodV()
CallShortMethod() CallShortMethodA() CallShortMethodV()
CallIntMethod() CallIntMethodA() CallIntMethodV()
CallLongMethod() CallLongMethodA() CallLongMethodV()
CallFloatMethod() CallFloatMethodA() CallFloatMethodV()
CallDoubleMethod() CallDoubleMethodA() CallDoubleMethodV()
CallNonvirtualVoidMethod() CallNonvirtualVoidMethodA() CallNonvirtualVoidMethodV()
void
CallNonvirtualObjectMethod() CallNonvirtualObjectMethodA() CallNonvirtualObjectMethodV() jobject
CallNonvirtualBooleanMethod() CallNonvirtualBooleanMethodA() CallNonvirtualBooleanMethodV() jboolean
CallNonvirtualByteMethod() CallNonvirtualByteMethodA() CallNonvirtualByteMethodV() jbyte
CallNonvirtualCharMethod() CallNonvirtualCharMethodA() CallNonvirtualCharMethodV() jchar
CallNonvirtualShortMethod() CallNonvirtualShortMethodA() CallNonvirtualShortMethodV() jshort
CallNonvirtualIntMethod() CallNonvirtualIntMethodA() CallNonvirtualIntMethodV() jint
CallNonvirtualLongMethod() CallNonvirtualLongMethodA() CallNonvirtualLongMethodV() jlong
CallNonvirtualFloatMethod() CallNonvirtualFloatMethodA() CallNonvirtualFloatMethodV() jfloat
CallNonvirtualDoubleMethod() CallNonvirtualDoubleMethodA() CallNonvirtualDoubleMethodV() jdouble

LINKAGE:

Indices in the JNIEnv interface function table.

Источник

Оцените статью
toolgir.ru
Adblock
detector