简体   繁体   中英

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.

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()".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM