Is there a way to get class name as a string from jclass ?
void Callback() {
if(env == NULL || gObj == NULL) return;
jclass cls = env->GetObjectClass(gObj);
if(cls){
jmethodID mid = env->GetMethodID(cls, "MyMethod", "()V");
if(mid)
env->CallVoidMethod(gObj, mid, NULL);
else
printf("mid is null\n");
}
}
In the above code, env & gObj are global variables. In some cases, I can get a valid value for 'mid', but in some cases GetMethodID returns null. So, I'm guessing that in such cases, GetObjectClass is returning a different class than expected(which is quite possible). Is there a way to get the class name as a string using jclass and jobject ?
[680 byte] By [
kteegalaa] at [2007-11-27 7:34:17]

# 5
I realized later that it's a java method and I tried to get toString() method.
if(env == NULL || gObj == NULL) return;
jclass cls = env->GetObjectClass(gObj);
if(cls){
jmethodID mid = env->GetMethodID(cls, "toString", "()Ljava/lang/String;");
if(mid)
jstring str = (jstring) env->CallObjectMethod(gObj, mid, NULL);
else
printf("mid is null\n");
}
The interesting part is when I tried calling toString() method , the methodID again returns null. So, looks like something is wrong with my global variable g_Obj itself. It is created from a java object in another jni method as follows:
g_obj = env->NewGlobalRef(jobj);
I'll look more into this..Thanks.
# 6
> void Callback() {
>if(env == NULL || gObj == NULL) return;
>jclass cls = env->GetObjectClass(gObj);
> if(cls){
> jmethodID mid = env->GetMethodID(cls,
> "MyMethod", "()V");
>if(mid)
>env->CallVoidMethod(gObj, mid, NULL);
>else
>printf("mid is null\n");
>
>
> In the above code, env & gObj are global variables.
> In some cases, I can get a valid value for 'mid', but
> in some cases GetMethodID returns null. So, I'm
> guessing that in such cases, GetObjectClass is
> returning a different class than expected(which is
> quite possible).
If it returns an unexpected class, what do you intend to do with it even if you have the name? Can't you use the JNI
IsInstanceOf
method to separate the bad objects from the good?
Jim S.