Reputation: 808
My goal is to build a Java-Class witch implements a method called from C++. This method gets the name of another Java-Method in the same class. Through the java-reflection API I want to get a reference to it (and call it later).
But the method called from C++ doesn't find the other Java method. If it runs from java it works fine. What do I miss?
JAVA:
public void myCPlusPlusFunc(String method){ // I'll pass "noparam" in here
logMessage("Searching for method " + method + "....");
for (Method m : this.getClass().getMethods()) {
if (method == m.getName()) {
logMessage("Found it!"); // never found when called through JNI/C++
// (...) invoke the method etc...
}
}
}
public void noparam() {
logMessage("noparam got called");
}
C++
JNIEnv *env = theJVMLoader->getENV();
jmethodID m = env->GetMethodID(getBeanClass(), "myCPlusPlusFunc", "(Ljava/lang/String;)V");
if (env->ExceptionCheck()) {
handleException();
ASSERT(FALSE);
return FALSE;
}
ASSERT(m);
if (m)
{
// "noparam" is the method i expect to find
jstring s = env->NewStringUTF("noparam");
env->CallVoidMethod(getBeanInstance(), m, s);
}
Upvotes: 0
Views: 168
Reputation: 2044
Im not sure if you can compare strings from jni with the equality == operator. Instead of
if (method == m.getName())
you should try
if (m.getName().equals(method))
there
Upvotes: 2