Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why my "CallIntMethod" always return 0

843829Jul 18 2006 — edited Jul 19 2006
I got a problem with "CallIntMethod". I try to use a java method to pass a number to a C++ method,and print it in that C++ method. But i let java pass something like 1,2,3.. the C++ method only print '0'.

/* my java code: */
public class returnInt{
		public int reInt(){
		int i = 3;
		return i;
	}
}
/* my C++ code*/
.......
/* Get the "returnInt" class. */
java_class = env->FindClass("returnInt");
if (java_class == NULL) {
cout << "error finding 'Foo' class\n" << endl;
}

/* Get the "enterInt" method ID. */
   method_id = env -> GetMethodID(
     java_class,
     "reInt",
     "()I"
   );
   if (method_id == NULL) {
     cout << "error finding 'reInt' method\n" << endl;
   }
   
    
   /* Call returnInt::reInt . */
   int javaint;
   javaint = env -> CallIntMethod(
     java_class,
     method_id,
     NULL /* args */
   );   
   
   /* print javaint */
   cout << javaint << endl;
...............
I think there must be some mistakes in my code..
How to use the "CallIntMethod"?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 16 2006
Added on Jul 18 2006
2 comments
298 views