Hi All,
Since I did noy get any response , I am reposting this....
I am trying to get a list of all public methods & fields in a given class. But I am having trouble. Listing below shows the code I am using. In the example I am trying to get all the public methods of java.lang.String .
But the code always prints out the 44 methods of java.lang.Class. . Can anyone help me out please ??
jclass cls = env->FindClass("java/lang/String");
if (cls == 0) {
fprintf(stderr, "Can't find hello class\n");
exit(1);
}
else
{
jclass jCls = env->GetObjectClass(cls); // Get the java.lang.Class for String
// Get Method ID of getMethods()
jmethodID midGetFields = env->GetMethodID(jCls, "getMethods","()[Ljava/lang/reflect/Method;");
env->ExceptionDescribe();
jobjectArray jobjArray = (jobjectArray)env->CallObjectMethod(jCls, midGetFields);
jsize len = env->GetArrayLength(jobjArray);
for(jsize i = 0 ; i < len ; i++)
{
jobject _strMethod = env->GetObjectArrayElement(jobjArray , i) ;
jclass _methodClazz = env->GetObjectClass(_strMethod) ;
jmethodID mid = env->GetMethodID(_methodClazz , "getName" , "()Ljava/lang/String;") ;
jstring _name = (jstring) env->CallObjectMethod(_strMethod , mid ) ;
char buf[128];
const char *str = env->GetStringUTFChars(_name, 0);
printf("\n%s", str);
env->ReleaseStringUTFChars(_name, str);
}
Cheers,
KHK