Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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: 66469
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SP: Welcome to the Ranch
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!