// get the JNIEnv instance JNIEnv env = JNIEnv.AttachCurrentThread(); // retrieve the object reference of the java object jobject javaObj = GetJavaObjectReference(); // get the ID of the method we want to call jmethodID methodId = env.GetMethodID(javaObj, "methodName", "()V"); // invoke the method env.CallVoidMethod(javaObj, methodId);
// get the JNIEnv instance JNIEnv env = JNIEnv.AttachCurrentThread(); // retrieve the object reference of the java object jobject javaObj = GetJavaObjectReference(); // get the ID of the method we want to call, which takes two string arguments jmethodID methodId = env.GetMethodID(javaObj, "methodName", "(Ljava/lang/String;Ljava/lang/String;)V"); // create the arguments jstring arg1 = env.NewStringUTF("arg1"); jstring arg2 = env.NewStringUTF("arg2"); // invoke the method with the arguments env.CallVoidMethod(javaObj, methodId, arg1, arg2);In this example, we again attached the current thread to the JNI environment and retrieved the object reference of the Java object we want to invoke a method on. We then obtained the ID of the method we want to call, which takes two string arguments. After that, we created the arguments using the NewStringUTF method and finally called the CallVoidMethod method to invoke the method on the Java object. Package library: The JNIEnv CallVoidMethod method is part of the Java Native Interface (JNI) library in the Java Development Kit (JDK) library. The JDK is a package library that contains tools and libraries for developing Java applications. The JNI library provides a way for Java applications to call native methods (written in C, C++, or other languages) and vice versa.