Link to home
Start Free TrialLog in
Avatar of eugeneng
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,"append","(Ljava/lang/String;)Ljava/lang/StringBuffer");

(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!!

Avatar of anhphuongnn
anhphuongnn

Hi eugeneng,


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(jmsgIn);



make sure append method is'nt static method.

best regard!

PhuongNguyen


Avatar of eugeneng

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
Avatar of muhotrepius
muhotrepius

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
u r right muhotrepius, thanx