dcsimg
Wrong Method Id error while calling a java method from c.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   haritasarma_nimishakavi
Posted On:   Friday, August 10, 2001 12:45 AM

Hi the following is java code public class Callbacks { public void callback(int depth) { if (depth < 5) System.out.println("In Java, depth = " + depth); else System.out.println("Number exceeds five"); } } This is my c code main(int argc, char **argv ) { jclass cls; jmethodID mid; JavaVM *jvm; int value=1; //jthrowable jthr; JNIEnv *env; JavaVMInitArgs vm_args; jint res; jint jver; JavaVMOption options[3]; options[0].optionStri   More>>

Hi the following is java code


			
public class Callbacks {


public void callback(int depth) {
if (depth < 5)
System.out.println("In Java, depth = " + depth);
else
System.out.println("Number exceeds five");
}


}



This is my c code




			
main(int argc, char **argv ) {

jclass cls;
jmethodID mid;
JavaVM *jvm;


int value=1;
//jthrowable jthr;

JNIEnv *env;
JavaVMInitArgs vm_args;
jint res;
jint jver;
JavaVMOption options[3];

options[0].optionString = "-Djava.compiler=NONE"; /* disable JIT */
options[1].optionString = "-Djava.class.path=d:\native"; /* user classes */
options[2].optionString = "-Djava.library.path=d:\jdk1.2.2\lib"; /* set native library path */
//options[3].optionString = "-verbose:jni"; /* print JNI-related messages */


vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = TRUE;



/* Setup the environment */
JNI_GetDefaultJavaVMInitArgs ( &vm_args );

//vm_args.classpath = "d:\jdk1.2.2\lib\tools.jar;d:\jdk1.2.2\lib\rt.jar;d:\native"; //PATH of the JAVA Classes
//printf("I m here now %s
",vm_args.classpath);

//printf("the value of jvm %d
",vm_args.version);

res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args );

printf("I m here now at response
");



/* Find the class we want to load */
//cls = (*env)->FindClass( env,);

cls = (*env)->FindClass(env, "Callbacks" );
printf("I m here now at cls id %d
",cls );

mid = (*env) ->GetMethodID(env,cls, "callback", "(I)V" );

printf("I m here now at bfore method call id %d
",mid);

(*env)->CallVoidMethod(env, cls, mid, value);
printf("after methodcall id %d
",mid);


(*jvm)->DestroyJavaVM(jvm);
}



when I am executing the program I am gettin an error message
FATAL ERROR in native method: Wrong method ID used to invoke a Java method

Why this is happening. Pl .let me know

   <<Less

Re: Wrong Method Id error while calling a java method from c.

Posted By:   jackson_mccann  
Posted On:   Friday, August 17, 2001 07:11 AM

The prototype for CallVoidMethod is CallVOidMethod(JNIEnv*env, jobject obj, jmethodID methodID, ...);

The second parameter is an object of the type that you want to call the method on, in this case a callback.

You need to create a new object of type Callback and then invoke you method call on it.

Jackson
About | Sitemap | Contact