JniHelper error: Failed to find static method id of

Hi!

So I am about to call java func from cpp in cocos2d-x using this code:

void HelloWorld::menuCloseCallback(Ref* pSender)
{
	JniMethodInfo t;

	if (JniHelper::getStaticMethodInfo(t,
	    "org/cocos2dx/cpp/AppActivity",
	    "sayHello",
	    "(Ljava/lang/String;I;)Z;")) {

	      const char* myName = "Beautiful Name";
	      int times = 3;

	     jstring stringArg1 = t.env->NewStringUTF(myName);
	     jboolean retV = t.env->CallStaticBooleanMethod(t.classID,
	         t.methodID,
	         stringArg1,
	         times);

     t.env->DeleteLocalRef(t.classID);
	     t.env->DeleteLocalRef(stringArg1);
	}
}

And my AppActivity:

	public static boolean sayHello(String to, int times)
	{
		Log.w("myApp", "BOOOOLLLLL");
		return true;
	}

But when I try the app it returns the error, Failed to find static method id of sayHello can u find the issue here?

Thanks!

It should be “(Ljava/lang/String;I)Z”. There is a solution for this kind of problems: https://github.com/fnz/EasyJNI Your code will look like

EasyJNI::callStaticBooleanMethod("org/cocos2dx/cpp/AppActivity", "sayHello", "Beautiful Name", 3); 

And that’s it. Alternatively you can grab upstream version on JniHelper: https://github.com/cocos2d/cocos2d-x/blob/v3/cocos/platform/android/jni/JniHelper.h (and .cpp), EasyJNI is merged there for 3.11, just change EasyJNI to JniHelper in the call above

It works like a charm now, thank u SO MUCH! I really appreciate your time :smile: