• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JNI

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I'm having trouble grasping the JNI concept:
I have a method in an .java file that sends a String array to my native code,which is written in C. I'm trying to manipulate this String array (just for educational purposes) and return the manipulated String array back to my Java code.
Can anyone teach me the right way to access the elements in the String[] in C? And what do I have to do to manipulate the array in C. I'm familiar with process of making a header file from Java, etc. It's just the C part that I'm struggling with..
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OKB,
Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
Thanks,
Cindy
PS: I am no C person - so I will leave this for others to reply to.
 
Ole Kristian
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that wasn't the reply I was hoping for Cindy...
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are just starting with JNI it might be better to deal with passing in a primative type and returning a primative type first, before dealing with Strings.
As strings are an Object there is some complicated casts and object gets required which can be difficult. And also C uses ASCII/ANSI while java uses Unicode so there are quite a few 'gotchas'.
Note also that while C strings are mutable, java strings are not so when you manipulate the string in C you will not be changing the original in java, so will need to pass back the result.
There is quite a good java tutorial on the sun site for JNI and I would suggest that as a good start if you still want to play with Strings ;-)
 
grapes are vegan food pellets. Eat this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic