Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse java  build path 6 57
maven project error 5 55
JavaFX TableView not displaying correctly 3 18
Is Applet the way to go for my drag and drop system? 8 14
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…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

773 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