Solved

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

Posted on 2001-09-03
4
985 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 40
Java syntax, or is it Selenium 6 43
Eclipse Java import and method not resolved 4 82
Java array 10 64
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

726 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