jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Returning String array from C program to Java(JNI) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Returning String array from C program to Java(JNI)" Watch "Returning String array from C program to Java(JNI)" New topic
Author

Returning String array from C program to Java(JNI)

Ann Johnson
Greenhorn

Joined: Jun 22, 2004
Posts: 14
How can I return a string[] from a cprogram to a java program?

private native String[] readRFIDData();

JNIEXPORT jobjectArray JNICALL Java_RfidDM_readRFIDData
(JNIEnv *, jobject);


Above is the definition of a jni method .
I have gone through the sample code, but they explain how to return arrays from C++.

Can someone please suggest? I am not good at C.

Much thanks,
Ann
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You want NewObjectArray(), NewStringUTF() etc.

See this article. As that site looks a little ropy, here is the relevant code extracted.

Note that ArrayHandler is the name of the Java class for which a native method is being implemented, in this example. It is not something you'll use.
[ November 16, 2004: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ann Johnson
Greenhorn

Joined: Jun 22, 2004
Posts: 14
Thank You Peter.
That worked well...
Vince Landi
Greenhorn

Joined: Jul 29, 2012
Posts: 1
Almost 8 years later, I must also add: thank you Peter!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Returning String array from C program to Java(JNI)