eugeneng
asked on
help (JNI)!! can't retrieve StringBuffer::append(String)'s method ID!!
I'm trying to call the method StringBuffer append(String) in the JNI native method, but I couldn't retrieve the append(String)'s method, what's wrong with my code below :
mID= pEnv->GetMethodID(sbcls,"a ppend","(L java/lang/ String;)Lj ava/lang/S tringBuffe r");
(sbcls is the StringBuffer's class id)
I could use the above pEnv,sbcls to retrieve the void setLength(int)'s methods ID, but it just don't work on StringBuffer append(String), why ? help please!!
mID= pEnv->GetMethodID(sbcls,"a
(sbcls is the StringBuffer's class id)
I could use the above pEnv,sbcls to retrieve the void setLength(int)'s methods ID, but it just don't work on StringBuffer append(String), why ? help please!!
ASKER
this doesn't work, because "append(String)" return StringBuffer, you won't be able to retrieve method ID of "void append(String)" because this function doesn't exist, to prove that, I tried your code, it failed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
u r right muhotrepius, thanx
jclass sbcls = pEnv->FindClass("class name");
if(sbcls == NULL)
{
printf("FindClass fail");
}
jstring jmsgIn = pEnv->NewStringUTF("abc");
pEnv->CallVoidMethod(
jobject,
pEnv->GetMethodID(sbcls, "append", "(Ljava/lang/String;)V"),
jmsgIn);
pEnv->DeleteLocalRef(jmsgI
make sure append method is'nt static method.
best regard!
PhuongNguyen