Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Returning String array from C program to Java(JNI)

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1970
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ann Johnson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Peter.
That worked well...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost 8 years later, I must also add: thank you Peter!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also must add, after 12 years, thank you Peter! Very helpful!
 
Marshal
Posts: 69395
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SP: Welcome to the Ranch
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic