java - Get fully-qualified class name from jclass (JNI) for use in FindClass -
let's assume hav instance of jclass:
auto objectclass = env->getobjectclass(obj); exception_return(env);
on next line, want name of class , store can use findclass
later on.
i've tried using getname()
method returns java class name , can't use in findclass
. here code getname()
approach:
std::string getobjectclassname(jnienv* env, jobject javaobject) { auto javaclass = env->getobjectclass(javaobject); exception_return(env); auto javaclassclass = env->findclass("java/lang/class"); exception_return(env); auto javaclassnamemethod = env->getmethodid(javaclassclass, "getname", "()ljava/lang/string;"); exception_return(env); auto javaclassnamejstring = (jstring)env->callobjectmethod(javaclass, javaclassnamemethod); exception_return(env); auto javaclassnamec = env->getstringutfchars(javaclassnamejstring, 0); exception_return(env); std::string javaclassname(javaclassnamec); env->releasestringutfchars(javaclassnamejstring, javaclassnamec); exception_return(env); return javaclassname; }
notice returned class name can't used in findclass()
method. there simple way class name jclass
object?
Comments
Post a Comment