Search code examples
javaandroidjava-native-interfacejavah

Why am I getting an error using Jni onload but not using javah's output?


I have this java method:

public static native void processBuffer(ByteBuffer bb);

with javah

JNIEXPORT void JNICALL Java_com_lan_factorial_IssmJni_processBuffer
  (JNIEnv *env, jclass klass , jobject buf)

work perfectly

with Jni onload

static JNINativeMethod method_table[] = {
        {"fac"      ,     "(J)J" , (void *) factorial},
        {"getBuffer",     "()[D" , (void *) getBufferNative},
        //{"processBuffer", "(Ljava/nio/ByteBuffer)V", (void *) fillBuffer}};

The others method in this table works, exept the last one which correspond to the method generate from javah above. And of course if I do JNI onload i will have a method call fillBuffer.

Can someone explain why javah works but not jni_onload. Did I do something wrong? I have other methods using jni_onload so I want to stay away from javah.

Thanks


Solution

  • You have a missing semicolon in the method signature. It doesn't 'correspond' at all. Don't guess at native method signatures: use the output of javap -s. Cut and paste.