Unable to call the non-Static Java Method from C/C++
843829Dec 2 2007 — edited Dec 6 2007Hi,
I am calling Java methods from C/C++ using JNI.
Now I can easily call the main method, but I am unable to call other non-static methods.
Signatures created by "javap -p -s HelloWorld" are given below:
-------------------------------------------------------------------------
javap -s -p HelloWorld
Compiled from "HelloWorld.java"
public class HelloWorld extends java.lang.Object{
public HelloWorld();
Signature: ()V
public static void main(java.lang.String[]);
Signature: ([Ljava/lang/String;)V
public void calling(java.lang.String);
Signature: (Ljava/lang/String;)V
}
---------------------------------------------------------------------------
C/C++ code is given below:
---------------------------------------------------------------------------
jclass cls = env->FindClass("HelloWorld");
if (cls != NULL)
{
jmethodID midMain = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
if(midMain != NULL)
env->CallStaticVoidMethod(cls, midMain, NULL);
jmethodID midCalling = env->GetMethodID(cls,"calling","([Ljava/lang/String;)V");
if (midCalling!=NULL)
{
jstring StringArg = env->NewStringUTF("\nCalled from the C Program\n");
env->CallVoidMethod(cls,midCalling,StringArg);
}
}
---------------------------------------------------------------------------
Main method has not problem. It works fine but when I call the 2nd non-static method i.e. "calling", it fails.
If I change the signatures of the calling function from non-static to static it works fine.
Kindly help me to resolve this problem.
Regards,
Ahmad Jalil Qarshi