Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

jmethodID is NULL

843829Jul 31 2002 — edited Aug 1 2002
I'm doing something similar to the following example and getting a methodID == NULL. Any ideas?

Here is the example:
#include <stdio.h>
#include <jni.h>
#include "Callbacks.h"

JNIEXPORT void JNICALL
Java_Callbacks_nativeMethod(JNIEnv *env, jobject obj, jint depth)
{
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "(I)V");
if (mid == 0) {
return;
}
printf("In C, depth = %d, about to enter Java\n", depth);
(*env)->CallVoidMethod(env, obj, mid, depth);
printf("In C, depth = %d, back from Java\n", depth);
}

__
class Callbacks {
private native void nativeMethod(int depth);
private void callback(int depth) {
if (depth < 5) {
System.out.println("In Java, depth = " + depth + ", about to enter C");
nativeMethod(depth + 1);
System.out.println("In Java, depth = " + depth + ", back from C");
} else
System.out.println("In Java, depth = " + depth + ", limit exceeded");
}
public static void main(String args[]) {
Callbacks c = new Callbacks();
c.nativeMethod(0);
}
static {
System.loadLibrary("MyImpOfCallbacks");
}
}

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2002
Added on Jul 31 2002
5 comments
623 views