JNI: calling a method from C ++ that takes an object

I have a simple problem and cannot find the answer. I wrote a method in C ++ that should call a method in Java that takes an object. For example, my Java code has:

public class MyClass {

    public class ReturnType {
    ...
    }

    public void methodToBeCalledFromC( ReturnType obj ) {
    ...
    }
}

And my C ++ has:

const jclass classID = s_env->FindClass( className );
const jmethodID methodID = s_env->GetMethodID( classID, "methodToBeCalledFromC", "(LMyClass;)V" );

// The call.handler() function returns a reference to the ReturnType object
// This produces a compilier warning and causes a seg-fault.
s_env->CallVoidMethod( call.handler(), jmid, userInfo );

I check the classID and methodID, and it call.handler()returns the jbject that I called NewGlobalRef(), so I think everything is fine.

Is it possible to transfer the task in this way?

+3
source share
1 answer

Check the compiler warning - this may tell you something important!

+3
source

All Articles