Android: calling Java class from C++ Native Activity-Collection of common programming errors
Not sure what is causing your error (you do not indicate where the lines are, or the particular line where you are having difficulty debugging), but I will go ahead and point out a few quick mistakes I see.
One first mistake is you need to use CallStaticObjectMethod
since you are calling a static method. Your jmethodid findClass
has a methodID, not a class, which is misleading and wrong. You also have two parameters, but you seem to be only passing one parameter.
Basically, you need:
(env)->GetStaticMethodID(jclass,"method name", "Parameter list")
–jclass is the class reference –“method name” is the name of the method IN quotes –“Parameter list” is the list of parameters, which you need to look up syntax.
Skipping a few things…To call your stuff you need:
(env)->CallStaticObjectMethod(jclass,jmid,parameter1,parameter2)
–jclass is once again the class that has the static method. –jmid is the java method id which you get from the function above. –parameter1 and parameter2 are the parameters required for the java method.
Lastly, I think this may just be preference, but I would not attach the thread to the JVM until you have all the necessary information to make the jump into the JVM.