This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes How return char array from native method to Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How return char array from native method to Java?" Watch "How return char array from native method to Java?" New topic
Author

How return char array from native method to Java?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
I have a JNI method that creates a char[] array and then will return it do the java program that called it. how do i do this? Do I have to create a jcharArray? how do I do that?
Basically what I want to do is: (pseudo code)

How would I do something like that?
Also, related:
1. Can I return a jobject (or something else) for an object of a non-"standard" class? For example, IP_ADAPTER_INFO (found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/ip_adapter_info.asp )
2. Anyone know of a really good JNI explanation site? The Sun stuff is not the best.
[ March 04, 2003: Message edited by: Robert Paris ]
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
Well, I finally figured it out. Here's the code for anyone who's interested:

That's it! However: does anyone know if there's any cleanup I need to do? Is there anything else I need to do to make sure the jbyteArray is returned but can be garbage collected later and that there are no "leaks?"
[ March 04, 2003: Message edited by: Robert Paris ]
 
jQuery in Action, 2nd edition
 
subject: How return char array from native method to Java?