Solved

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

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

Technology Partners: 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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

707 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