Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now