TooManyEduardos
TooManyEduardos

Reputation: 4404

How can I pass 2 byte[] from JNI to Java

I have a java method, like this:

public static native void receiveCallback(byte[] value1, byte[] value2);

In JNI I can reach the class and I can reach the method, but my parameter list is incorrect. I am trying to call the method like this:

jmethodID testJavaMethod = (java_environment)->GetMethodID(clazz, "receiveCallback","([B[B");

I then get a NoSuchMethod exception at runtime.

I followed multiple SO questions, including this one JNI - How to callback from C++ or C to Java?, but I'm still stuck.

Any suggestions?

Thanks.

Upvotes: 0

Views: 175

Answers (1)

user2543253
user2543253

Reputation: 2173

If you want to call back into Java, the implementation must be in Java. You need

public static void receiveCallback(byte[] value1, byte[] value2) {
    // do something with value1 and value2
}

And to get the id of a static method you need to use "GetStaticMethodID". Also to call it you will have to use "CallStaticVoidMethod()".

Upvotes: 1

Related Questions