I have a Java function which returns a singleton instance of a Class
public static synchronized MyClass getInstance() throws MyClassException{
if (instance == NULL){
// create
}
return instance;
}
I want to call this through C++ code, but when I do, it returns a NoSuchMethodError.
cls = jenv->FindClass("MyClass");
if (cls == NULL)
{
//error handling
}
mid = jenv->GetStaticMethodID(cls, "getInstance", "()LMyClass");
if (mid == NULL)
{
//error handling
}
When I run:
javap -s -p on MyClass, I get the signature:
public static synchronized MyClass getInstance() throws MyClassException;
Signature: ()LMyClass;
If I change the function signature to void in the Java class, the GetStaticMethodID call works as expected.
Do I need to setup a jobject to expect the return value from the call?
Is this possible without calling GetStaticMethodID first?