?
Solved

help (JNI)!! can't retrieve StringBuffer::append(String)'s method ID!!

Posted on 2001-09-03
4
Medium Priority
?
1,024 Views
Last Modified: 2013-12-29
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!!

0
Comment
Question by:eugeneng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:anhphuongnn
ID: 6452246
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


0
 

Author Comment

by:eugeneng
ID: 6455116
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.
0
 

Accepted Solution

by:
muhotrepius earned 200 total points
ID: 6456406
Dude you missed one ; at the end of the return type.
It should be "Ljava/land/StringBuffer;"
This works on my NT :

   jclass strbuf;
   strbuf = (*env)->FindClass(env, "java/lang/StringBuffer");
   if(NULL == strbuf)
      MessageBox(NULL, "Cannot find class", "Error", MB_OK);
   else {
      jmethodID append = (*env)->GetMethodID(env, strbuf, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
      if(NULL == strbuf)
         MessageBox(NULL, "Cannot find method", "Error", MB_OK);
      else  
         MessageBox(NULL, "OK", "Ok", MB_OK);
   }
0
 

Author Comment

by:eugeneng
ID: 6456492
u r right muhotrepius, thanx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question