Class name from jclass in JNI

前端 未结 1 709
难免孤独
难免孤独 2021-02-13 22:03

This is probably a daft question that reveals a lack of understanding of JNI. I\'m writing a C++ program that encapsulates the Java VM: I\'m calling functions within the VM usin

1条回答
  •  广开言路
    2021-02-13 22:31

    The jclass instance is your object on which a method will be invoked; you'll need to look up the getName method ID on the Class class, then invoke it on the jclass instance using CallObjectMethod to obtain a jstring result.

    So in short yes, you just call the getName function and look at the jstring result.

    EDIT

    (error handling elided)

    JNIEnv* env = ...;
    // substitute your desired class's specifier for "java/lang/Class"...
    jclass cls = env->FindClass("java/lang/Class"); 
    jmethodID mid_getName = env->GetMethodID(cls, "getName", "()Ljava/lang/String;");
    jstring name = env->CallObjectMethod(cls, mid_getName);
    

    0 讨论(0)
提交回复
热议问题