How to return array of String to a java program.! ??

Hi All,
I am new to JNI programming. so trying with simple example. I am having one problem. I have one array of String in my Java program. I want to reverse all the elements in this array and want back this new array in the same form i.e. array of string. So how can I do this ??
Please guide me.....
The function of defination of array in my java code is
public native String[] getReverseStringArray(String[] arrString);
where as my array is like:
String[] arrStr = {"one", "two", "three", "four", "��������","�c��","�J�^�J�i"};
and I am calling function in C file like:
arrStr = employee.getReverseStringArray(arrStr);
and the function defination in my c file is
JNIEXPORT jobjectArray JNICALL
Java_Emp_getReverseStringArray (JNIEnv *env, jobject obj, jobjectArray arr)
// some code will come here......
So can anybody tell me how to do this ??
Thanx in advance...
Pandurang
[email protected]

Hi,
this is quite simple. Here an example function that works like this:
JNIEXPORT jobjectArray JNICALL Java_cadagent_ugopen_UgAssembly_jni_1getStructure
(JNIEnv *env, jclass cls, jstring part)
jobjectArray retvals = NULL;
jstring j_val = NULL;
int child_count = 5;
/* initialize return array */
j_val = (*env)->NewStringUTF(env, "");
retvals = (*env)->NewObjectArray(env, child_count, (*env)->FindClass(env, "java/lang/String"), j_val);
for (i=0;i<child_count;i++)
j_val = (*env)->NewStringUTF(env, "some text");
(*env)->SetObjectArrayElement(env, retvals,i, j_val);
return retvals;
Hope this answers you question.

Similar Messages

  • Memory leak when when returning array of strings to calling vb program

    Hi,
    I have a VBA script running in Excel 2010 which invokes a java swing app using the ActiveX bridge.
    Below is a short snippet of what happens
    Set Requester = CreateObject("ERequester.Bean.1")
    Set RequestResult = Requester.executeRequest(some parameters.....)
    Dim dArray
    dArray = RequestResult.getResultStringArray()
    Erase dArray
    At the Java side (using jdk1.6.0_26) the getResultStringArray() function is as given below
    public String[] getResultStringArray()
    String[] ticValues= new String[10000];
    Some code which creates local string objects and sets it to each position in the array
    return ticValues;
    After calling RequestResult.getResultStringArray() and releasing the array at VBA side the stings are still present in jvm memory and are not garbage collected
    As the function gets called multiple times, JVM continuously keeps increasing its memory footprint until it reaches the max limit and causes OutOfMemoryError.
    Any idea what may be going wrong?
    Thanks in advance

    Whne the program starts, you could create an array of all control references (from the pane property: "Controls[]") and get their label. To get a reference from the label, just search the label array and index into the array of references to get the corresponding reference.
    Still, this method is flawed.
    You can have multiple controls with the same name, which would confuse things.
    How about controls within cluster, etc.
    I think somebody wrote a tool once for this, but I don't remember where I saw it.
    LabVIEW Champion . Do more with less code and in less time .

  • How to return array of object

    public class A{
    public class B{
    publc C[] sample()
    int i=0;
    ResultSet rset = s.executeQuery("select name, id  from emp ");
    while(rs.next()){
    name = rset.getString("nam");
    id = rset.getInt("id");
    c.setName(name )
    c[i].setId(id)
    return c[]
    public class C{
    // here i have getter and setter metod for name & id
    When I try to return the object c[]..i am getting "cannot conver from C to C[]".
    Can u pls help me, how to return array of object and how to get name and id values in other class using this array object
    Thanks for ur help

    public class Starting{
    public long empID;
    Data data = new Data();
    Value[] value;
    int count = 0;
         public static void executeDe(){
              value = new Value[100]
              try{
                     data.getDetails()
                     processDetails(value);
                   }catch(Exception e){e.printStackTrace();}
         public static void processDetails(Value[] value){
         count = data.i;
              int i;
              for(i=0;i<count;i++){
                  empID=value.getempID(); \\ here i am not getting all values..... am getting only last value of the array
    public class Data{
    public long empID;
    public int i=0;
    static Value[] value = new Value[100];
    public static Value[] getDetails(){
    Connection con=null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@" + hostname + ":1521:" + sid, user, password);
    System.out.println(" conn " + con);
    System.out.println("");
    Statement s=con.createStatement();
    try{
         ResultSet rset = s.executeQuery("select EMPID from Employee ");
         while(rset.next()){
    empID = rset.getLong("EMPID");
    value[i].setCycleID(cy_i);
    i++;
         rset.close();
         con.close();
    }catch (SQLException sqle){sqle.printStackTrace();}
         finally{
              try{
              s.close();
         con.close();
              }catch(SQLException e){e.printStackTrace();}
    catch(Exception e){e.printStackTrace();}
    return value;
         public class Value {
         public static long cycleID;
              public static void setempID(long empID) {
                   Value.empID = empID;
              public static long getempID() {
                   return empID;
    This is my actual code..... I am able to set the values in Value class from Data class using getDetails() method, which is returning array of value object.
    In Starting class, I am trying to get values using value[i].. i am getting last value of the array. This is my actual problem... here i want to get all values.
    Please help me how to resolve this.

  • How to display a oracle table from a java program?

    How to display a oracle table from a java program.
    Hello friends, I have written a Java program, using oracle 10g as backend.
    I want to display a oracle table as output. Im not getting how to display oracle table as a output table.. Pls help me
    Thank you

    jayanthds, you're not going to get a satisfactory
    answer to this here. it's too big a task to justbe
    quickly outlined in a forum - the reply "all youneed
    to do is to query you table and return it asJTable"
    is worthless, for example, since the solution to
    any problem can be distilled to such a
    soundbite, if need be. doesn't make the solutionany
    simpler
    essentially you're asking "how do I write adatabase
    application?". all you'll get is snippets of code
    that, when fitted together, will eventually helpyou
    do this, but you'll spend days and days comingback
    saying "right, I've done that, now what?" until
    either you or the forum gets frustrated with the
    whole affair and the process stops
    there are entire books written about this subject,
    and countless tutorials and guides on theinternet.
    you're better off going down that routehehehe.well, it's true! I used to have a manager that would outline the solution to a problem in a few lines of pseudocode, and then firmly believe that the actual solution would be just as brief and simple. shame his pseudocode included such lofty abstractions as "reformat all data"

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How to call j2me emulator instance from a java program?

    hi,
    how to call j2me emulator instance from a java program?
    i tried public void startApp(){
    try{
    platformRequest("tel:+5550000");
    }catch(Exception e){
    e.printStackTrace();
    from a j2me midlet itself,
    but it gave illegal access exception.
    do i need any hardware phone connected to my pc?
    please help.

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    import java.util.*;
    public class OpenExplorer{
    public static void main(String args[]){
         new OpenExplorer();
    public OpenExplorer(){
         try{
         String command = "explorer C:";
         // or String command = "cmd /c explorer C:";
         Runtime runtime = Runtime.getRuntime();
         Process process = runtime.exec(command);
         int exitVal = process.waitFor();
         System.out.println("Exit Value: " + exitVal);
         } catch(Exception e){
         e.printStackTrace();
    }

  • How to run an exe file in a java program

    Hi,
    Can somebody tell me how to run an exe file in a java program.
    Thank you!

    Yes, java.lang.Runtime.exec().
    Read this carefully before you do:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Don't write a line of code before you're reviewed and understood the article completely. - MOD

  • How to extract .sit files(in MAC)  using java program

    Hi,
    please help me , i want to simple program for
    " how to extract .sit files(in MAC) using java program"
    that sit files same as zip files in windows..[                                                                                                                                                                                                                                                                                                                                   

    Thanks for reply...
    but i search in the google about this topic...there is no results will appear..
    the problem is "i have to run program in the MacOS like extract all the
    .sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
    please do the needful..i am waiting for ur reply,,,

  • How to request Administrator or root to execute java programs?

    How to request Administrator or root to execute java programs when the user is not enough permission?
    as same as following image:
    Windows : http://img151.imageshack.us/img151/6113/winrw5.gif
    Linux: http://img374.imageshack.us/img374/8990/linuxsj4.png
    Edited by: lauangus on 2008?10?13? ??9:15

    Dear Sys Admin,
    Would you please grant me and my group enough rights to do the tasks that have been assigned to us, we are using the following programs. They will need to asccess....
    Sincerely,
    lauangus
    Note: this will usually have to be accompanied by appropriate supervisor signatures and endorsements.

  • How can I return Array of String to client

    Hi all,
    I am a new learner about web services, can any one tell me how to return of get a String of array from OMElement ?
    I have two server side method want to create, first method receive an array of string and second method return an an array of String. How should I implement it.
    public org.apache.axiom.om.OMElement OneWayRequest() {
              //How Please help me
    public void LoadDummyNumberForInventory(
         org.apache.axiom.om.OMElement loadDummyNumberForInventory0) {
    //How get the String array ?
    }

    Hi all,
    I am a new learner about web services, can any one tell me how to return of get a String of array from OMElement ?
    I have two server side method want to create, first method receive an array of string and second method return an an array of String. How should I implement it.
    public org.apache.axiom.om.OMElement OneWayRequest() {
              //How Please help me
    public void LoadDummyNumberForInventory(
         org.apache.axiom.om.OMElement loadDummyNumberForInventory0) {
    //How get the String array ?
    }

  • Problem returning array of strings

    Hi,
    I am trying to return an array of strings from C to Java.The function I am using is
    char rec[20][20];
    int num=0;
    /* incrementing num and copying into the array everytime a record is added*/
    JNIEXPORT jobjectArray JNICALL Java_jnimidlet_list_1rec
    (JNIEnv *env, jobject obj)
    jstring str;
    jobjectArray args = 0;
    jsize len = num;
    int i=0;
    args = (*env)->NewObjectArray(env, len,
    (*env)->FindClass(env, "java/lang/String"), 0);
    for( i=0; i < len; i++ )
    str = (*env)->NewStringUTF( env, rec);
    (*env)->SetObjectArrayElement(env, args, i, str);
    return args;
    In the java code:
    String []all=list_rec();
    when this function is called I get the error:
    Unhandled exception
    Type=GPF vmState=0xffffffff
    ExceptionCode=0xc0000005 ExceptionAddress=0x00000000 ContextFlags=0x0001003f
    Handler1=0x10f01530 Handler2=0x10026280
    Module=C:\wsdd5.5\wsdd5.0\ive\bin\j9.exe
    Module_base_address=0x00000000
    Offset_in_DLL=0x00000000
    EDI=0x0012fc14 ESI=0x10f01530 EAX=0x00020020
    EBX=0x00148e34 ECX=0x0017469c EDX=0x00020020
    EBP=0x00149d40 ESP=0x0012fbec EIP=0x00000000
    Thread: main (priority 5) (LOCATION OF ERROR)
    Thread: Gc Thread (priority 5) (daemon)
    Can anyone pls tell me how do I come out of this problem.
    Please help.
    Thanx in advance,
    pri_rav

    Hi Priya,
    I dont see any problem. I tried to work with your code it works fine without any exception. Please make sure all ur rec char buff contents are null terminated and your 'i' counter is initialized properly and stops properly. According to me there shouldn't be any problem with JVM. I hope you are aware of c programming,which doesn't check for array boundaries. You may accidentally go out of array size allocated. So my suggession is to check you rec buff going above any of the dimension. Put a watch on 'i' variable content as well. Try and let me know whether it solves your problem. If it doesn't reply me with more details. I will try helping you.
    Thanks,
    Regards,
    Ravikiran.

  • How to store Array of Strings in MS-Access

    Dear all,
    i am facing a problame from the couple of days can any one plzzzzzzz guide what should i do to over come my problame....>
    I want to store a String array in Microsoft Access database but i couldn't find the way how can i do so
    public class ArrayJDBC {
    /** Creates a new instance of ArrayJDBC */
    public ArrayJDBC() {
    public static void main(String[] args){
    System.out.println("main started");
    new ArrayJDBC().enterArray();
    System.out.println("main after data entry");
    public void enterArray(){
    Connection con = null;
    PreparedStatement pstm = null;
    String dataSource = "checkArray";
    String query = "INSERT INTO array(Object) VALUES(?)";
    String[] strArray = {"one","two","three"};
    con = new JDBCConnection().makeConnection(dataSource);
    try{
    pstm = con.prepareStatement(query);
    System.out.println("pstmt created");
    pstm.setObject(1,strArray);
    System.out.println("array seted as object");
    int r = pstm.executeUpdate();
    System.out.println("data updated "+r);
    pstm.close();
    con.close();
    }catch(SQLException se){
    System.out.println("Data could not be update "+se);
    this is my class the conncection is already established.
    i use updateObject() method but it doesnt work..
    plz guide me that how can i store
    strArray in Microsoft Access and also tell me that what should be the data type in my database i.e ms-access

    Well easiest way to do that is to create a single String where the values from array will be separated by some separator for example semicolon so you will get "one;two;three" this string you will store in database as a text, then when you read it back you need to parse it again to get an array of Strings. I am originally C# programmer there i would do serialization to XML and store it into database try looking here http://iharder.sourceforge.net/current/java/xmlizable/ they are creating XML Serializer.
    Peter.

  • How to return array of unsigned integer pointer from call library function node & store the data in array in labview

    I want to return array of unsigned integer from call library node.
    If anybody knows please help me
    Thanks & Regards,
    Harish. G.

    Did you take a look at the example that ships with LabVIEW that shows how to do all sorts of data passing to DLLs. I believe your situation is one of the examples listed. You can find the example VI in the "<LabVIEW install directory>\examples\dll\data passing" directory.

  • How to compare array of String with column of a table

    Hi,
    i have a array of string(say array is of length 1000). I want to
    compare those string in array with one table column
            - whether that table column has a string
                            if yes
                                            do nothing.
                            if no
                                            then insert that string into table.
            - whether table has obsolete row i.e, the one present in table and
    not in array
                            then delete that row.
    How do i go about this, because i see, it is not feasible to loop
    through array and search table to find new string OR loop through each
    row from table to find some obsolete row
    How can i accomplish this task more feasibly(without running query for
    each string, for comparission)? Is there any way to find this kind of
    problem. I would have been easy if i had to compare two tables(with
    UNION and INTERSECT), but it is not the case.
    thanks,
    kath.

    I'm not sure, whether I understand your problem correctly. Only two comments:
    - if both arrays are sorted, all can be done running exactly once simultaneously through both arrays.
    - if the column is marked as UNIQUE, all column strings will be different. I.e. you cannot insert the same string a second time.
    Regards  Thomas

  • Regarding How to return 2-D string [][]

    hi all
    I want to return 2-D String [][] at the end of following code. Also i will replace all Arraylist with string array. But i do not know what is the format for return String xx [][]
    regards and thanks
    pangqin
    while(rs.next()){
         String[] strArrayTemp=new String[numberOfColumns];
         for(int i=0;i<numberOfColumns;i++){
          if(rs.getObject(i+1)==null){
           strArrayTemp= "";
    }else{
    strArrayTemp[i]=rs.getObject(i+1).toString();
    ArrayRs.add(strArrayTemp);
    //return (ArrayList)ArrayRs.clone();
    //?@i wanna add return string [][] here to replace all arraylist

    String[][] whatever = ...;
    return whatever;What makes you think it's different from any other variable?

Maybe you are looking for

  • Acrobat 9 HTML to PDF conversion sets all checkboxes to checked - Duplicate question

    I am converting html files to pdf using Acrobat 9 pro. All of the check boxes and radio buttons come out checked. This is exactly the same as the following thread: Acrobat 9 HTML to PDF conversion sets all checkboxes to checked? That thread is old, b

  • Vbs script to manage aspect ratios in PowerPoint (16:9 vs. 4:3)

    Hello. Can someone help me with the following? I need a VBS script to make PowerPoint's default slide size to 16:9 from 4:3. Thank you for any help here. Jrene

  • Terminating event deactivation

    Hi , There is an terminating event of a task in a workflow builder which is activated . Can someone please suggest some tcodes from where the terminating events are displayed and can be deactivated . Also please let me know does the tcode SWETYPV dis

  • 10.8.2 audio jack issue fix with a 15" retina Macbook Pro

    OK so I had an issue where I could not get the headphone jack to work whatso ever with multiple pairs of headphones. I barely used the port so I i'm not sure what exactly the problem is down to as I had recently installed a ton for new software thank

  • Connecting two Central Servers??

    Mohan, More info may be beneficial. If you are trying to share service objects across two environments, you will need to create a reference partition. If the two different Central Servers are truly on two different machines, you can connect their env