• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI accessing Integer Object

 
H Padia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JNI method to access java method which returns an Integer object. I do not want to return the primitive int type because this code will be modified to handle Generic objects. The following is what I have. I am not able to get the value of the Integer that I pass. The output at C++ side is something like


How can I get the actual value of Integer object that I pass, at the C++ end?

Please help.

Thanks,

-H

GenericPeer.cpp



GenericPeer.java


Data.java



Test.java (Main class)


 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value jobject is a pointer (yes, actual pointer. After all, this is C++) to the Integer object (or at least a pointer to something that represents the Integer object). To get its value you need to do the following:
- make sure it isn't NULL!
- get its class
- using the class, get the intValue() method
- call that method, the result is a jint.
 
H Padia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rob,

Your post helped me through.

 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would perhaps change one thing:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!