Current Position:Home > How to call object method (eg, CallIntMethod)in C?

How to call object method (eg, CallIntMethod)in C?

Update:10-11Source: network consolidation
I aslo get problem when I use "CallIntMehtod", the following is my program
public class test {
public int getvalue(int n)
System.out.println("cjf, welcome");
return n*n;
#include <jni.h>
int main() {
int res;
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
jclass cls;
jmethodID mid;
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 3;
// vm_args.options = options;
vm_args.ignoreUnrecognized = JNI_TRUE;
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); /* create VM */
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
printf("success create java VM \n");
cls = (*env)->FindClass(env, "test");/* find class */
if ( cls != (jclass)0 ) {
mid = (*env)->GetMethodID( env, cls, "getvalue", "(I)I" );/* get method ID */
if( mid != 0 ){
printf("First call to Java returns:%d\n", (*env)->CallIntMethod(env, cls, mid,2) );/* execute
method */
(*jvm)->DestroyJavaVM(jvm);/* destroy java VM */
fprintf(stdout, "Java VM destory.\n");
return 0;
when I compiled them and run it, I cann't get the expected result. the result is:
[email protected]/home/bss>./invoke
success create java VM
First call to Java returns:0
Java VM destory.
so ,what' wrong?

The Best Answer

Your method "getvalue" is not static.
You have to create an object of your class "test" and call the method with this object (not with the class) as parameter: CallIntMethod(env, obj, mid,2).
  • How to call object method (eg, CallIntMethod)in C? Update:10-11

    I aslo get problem when I use "CallIntMehtod", the following is my program public class test { public int getvalue(int n) System.out.println("cjf, welcome"); return n*n; invoke.c #include <jni.h> int main() { int res; J

  • Want to know how to debug the Business Object Method called from CRM Update:11-30

    Hi all, I have to debug a Method of a custom Business Object. This is being called when a certain action is performed on the CRM  ( CIC0 screen). I can not see an option to set an external break point in the Program of the Business Object Method. Thi

  • HOWTO: Expose Entity Object Methods to Clients Update:11-30

    By design, clients cannot directly access entity objects. The view object layer provides an extra layer of security--you can choose exactly what data and methods you want clients to see. This HOWTO describes the process of exposing an entity object m

  • How to manage optional output parameters in an object method ? Update:11-30

    Hi Abapers, I've a little coding point to clarify in object programming : I've defined an output method parameter as optional. I want to prevent execution error with the following test : IF et_my_ouput_paramer IS REQUESTED.    APPEND LINES OF lt_my_d

  • Why is String method called not Object method Update:11-30

    In the below program :: class Test      public void callMethod(Object o)           System.out.println("Object Method Called");      public void callMethod(String s)           System.out.println("String Method Called");      public stat

  • Connect to COM(OBJECTS/METHODS) FROM ABAP Update:11-30

    Dear all. How can I connect to COM objects/methods from abap? Could give me link to example.Yes this method raises and exception with this message Message ID:          FDT_CORE Message number:      085 DO_IM_DATETIME is not in the context The method

  • Access an objects method + no line terminator Update:11-30

    Hi, I've just found out that if you can use the objects methods by not terminating a line with semicolon; StringBuffer sb = new StringBuffer(); sb.append("A")     .append("B")     .append("C");Is this because the terminator c

  • Using null for parameterized "newInstance(Object [])" method in Object[]. Update:10-11

    I have a really serious problem. I am creating instances of specific classes by using reflection techniques. I am reading a flat file, finding class from its name and creating it by using its parameterized constructor. Example: line 1: Dummy("A"

  • Business Object Method is not Visible Update:10-11

    Hi Experts, I have created a custom business object and created a method for it in t-code SWO1. I am trying to use this object's method in one of workflow tasks. I entered the business object and I do not find the method in the method's list. I relea

  • Obtaining Object Methods Update:10-11

    Problem: I am working with a list of class which are all subclasses of an abstract class. I have created an object of each method by the following code: Dent Hor = new Horisontal(); Dent Hin = new Hinged(); Dent I = new Instant(); Dent V = new Vertic