Referance array passing to c++

hi,
from what i know, it is not possible to return a whole array back to java program, as java supports no pointers
so for my method what i have done is passed a static array to the native code and updated it from the c++ code so that when native code alters it, it should be altered in java automatically
but in actual this does not happen, any one has any ideas on this one?
i am giving my code below:
class DGlove
     public static int[] values = new int[7];
     public static boolean status = false;
     public static native void getValues(int[] array);
     public static native void connectDG();
     public static native void disconnectDG();
     public static native boolean getStatus();
     static
     System.loadLibrary("dg5dt");
public static void main (String[] args)
          connectDG();
          getValues(values);
          status = getStatus();
          System.out.println(status);
          for (int i =0; i<=6;i++)
               System.out.println(values);
//          if (status == true)
//          disconnectDG();
          status = getStatus();
          System.out.println(status);
          getValues(values);
          for (int i =0; i<=6;i++)
               System.out.println(values[i]);
//cpp file (native code)
# include "conio.h"
# include "DataGlove.h"
# include "DGlove.h"
# include "jni.h"
unsigned short arraydg15[17];
int arraydg5[6];
bool status=0;
DataGlove glove;
JNIEXPORT void JNICALL Java_DGlove_getValues
(JNIEnv *env, jclass obj, jintArray arr)
     jsize len = env->GetArrayLength(arr);
     if (status == 1)
          glove.GetSensorRawValues (arraydg15);
          // conversion from the 15 sensor array to the 5 sensor array
          arraydg5[0] = arraydg15[0];
          arraydg5[1] = arraydg15[3];
          arraydg5[2] = arraydg15[6];
          arraydg5[3] = arraydg15[9];
          arraydg5[4] = arraydg15[12];
          arraydg5[5] = arraydg15[16];
          arraydg5[6] = arraydg15[17];
          jint *body = env->GetIntArrayElements(arr,0);
          for (int i =0;i<=len;i++)
               body[i] = arraydg5[i];
JNIEXPORT void JNICALL Java_DGlove_connectDG
(JNIEnv *env, jclass obj)
     status = glove.Connect("COM1");
     printf("data glove status %d", status);
     getch();
JNIEXPORT void JNICALL Java_DGlove_disconnectDG
(JNIEnv *env, jclass obj)
     status = glove.DisConnect();
JNIEXPORT jboolean JNICALL Java_DGlove_getStatus
(JNIEnv *env, jclass obj)
     return status;
what i need to do is pass the array by referance to native c++ code , have it modified and get the values back in java

An array is a java object, and like any other object can be returned by a native (C) method. You just have to make the right JNI calls to create and populate the array.

Similar Messages

  • Arrays pass by value

    hi guys
    are primative arrays passed by value or passed by reference
    cheers
    spob

    Java uses pass by value. The references to the arrays
    are passed by value, though of course a copy of a
    reference refers to the same thing as the "original"
    reference does.I hope you got the support one!
    This is an automatically generated Delivery Status Notification.
    Delivery to the following recipients failed.
    [email protected]
    [email protected]

  • Error: Non-array passed to JNI array operations

    Can anyone see what I am doing wrong? I am trying to go through the array of objects example in the online JNI text book "The Java Native Interface Programmer's Guide and Specification" by Sheng Liang. The book and pertinent chapter can be found here:
    http://java.sun.com/docs/books/jni/html/objtypes.html#27791
    The error I received on running the program with the -Xcheck:jni switch is this:
    FATAL ERROR in native method: Non-array passed to JNI array operations
         at petes.JNI.ObjectArrayTest.initInt2DArray(Native Method)
         at petes.JNI.ObjectArrayTest.main(ObjectArrayTest.java:14)Without the xcheck switch, I get a huge error log file that I can reproduce here if needed.
    My c code with #ifdef _Debug statements removed for readability is listed below.  The location of the error (I believe) is marked:
    #include <jni.h>
    #include <stdio.h>
    #include "petes_JNI_ObjectArrayTest.h"
    //#define _Debug
    // error found running the program with the -Xcheck:jni switch
    //page 38 and 39 of The Java Native Interface Guide by Sheng Liang
    JNIEXPORT jobjectArray JNICALL Java_petes_JNI_ObjectArrayTest_initInt2DArray
      (JNIEnv *env, jclass class, jint size)
         jobjectArray result;
         jint i;
         jclass intArrCls = (*env)->FindClass(env, "[I");
         if (intArrCls == NULL)
              return NULL;
         result = (*env)->NewObjectArray(env, size, intArrCls, NULL);
         if (result = NULL)
              return NULL; 
         for (i = 0; i < size; i++)
              jint tmp[256]; // make sure it is large enough
              jint j;
              jintArray iarr = (*env)->NewIntArray(env, size);
              if (iarr == NULL)
                   return NULL; 
              for (j = 0; j < size; j++)
                   tmp[j] = i + j;
              (*env)->SetIntArrayRegion(env, iarr, 0, size, tmp);
              (*env)->SetObjectArrayElement(env, result, i, iarr); // ***** ERROR:  Non-array passed to JNI array operations
              (*env)->DeleteLocalRef(env, iarr);
         return result;
    }Here is my java code
    package petes.JNI;
    public class ObjectArrayTest
        private static native int[][] initInt2DArray(int size);
        static
            System.loadLibrary("petes_JNI_ObjectArrayTest");
        public static void main(String[] args)
            int[][] i2arr = initInt2DArray(3);
            if (i2arr != null)
                for (int i = 0; i < i2arr.length; i++)
                    for (int j = 0; j < i2arr[0].length; j++)
                        System.out.println(" " + i2arr[i][j]);
                    System.out.println();
            else
                System.out.println("i2arr is null");
    }Thanks in advance!
    Pete

    Niceguy1: Thanks for the quick reply!
    So far, I mainly see the usual differences between C and C++ JNI calls. Also, in the example you gave, they use a lot of casts, but that doesn't seem to make much difference to my output. Also, in the example, they create a 0-initilized int array, and use this class to initialze the class type of the Object array. I get the class type by a call to FindClass for a class type of "[I".  I'll try this their way and see what happens...
    Edit:  Changing the way I find the array element Object type did not help.  I still get the same error as previous.  Any other ideas would be greatly appreciated.
    Message was edited by:
            petes1234                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Time stamp & array passed in a cluster through DLL are not accepted by Teststand

    I am trying to pass  Timestamp & array data [string array]   in a cluster  from DLL  is not  getting recognized by testsand.
    The action module (DLL)  Output (cluster)  generates   error "System Level Exception.[Error Code: -17502] "
    the png file shows the cluster
    I spoke to NI support & they  suppose that its time stamp that generates error
    but some fields (numeric, string) i am able to read
    Attachments:
    clustererror.PNG ‏41 KB

    Hello aparab,
    here is a link to another forum, which solves your issue:
    time stamp, data type for dll:
    http://forums.ni.com/t5/LabVIEW/time-stamp-data-type-for-dll/td-p/1085375
    to summarize:
    there are two possibilities to pass a cluster with a timestamp from LV to TS:
    1. use a string for the timestamp, although a numeric double might be easier to work with in TestStand
    2. use packed library

  • FATAL ERROR in native method: Non-array passed to JNI array operations

    After stepping up to JDK 1.4.2 we started getting a hotspot error, I added -Xcheck:jni and it yielded the above error which was not existent in JDK 1.4.1 and for the life of me I cannot find out whats wrong:
    Native method dec:
    private native byte[] cost(final byte[] byte_array,
    final double minCostPerMeter,
    final int costFuncSelection,
    final double maxCostThreshold);
    Method call:
    ByteArrayInputStream
    inputByteStream = new ByteArrayInputStream(
    cost(output_byte_stream.toByteArray(),
    minCostPerMeter,
    costFunctionSelection.length,
    maxCostThreshold));
    An array is being passed I have no idea why it is complaing about the method call.
    Any help would be appreciated.
    -R

    What happens if you remove all the code from the JNI method - so it just calls and then returns?
    If it still occurs then I would expect that you have a memory problem in a piece of code before this one. Such problems can have no impact when run in one environment but cause failures in another becomes some other legitimate piece of data moved.
    If it doesn't then I would expect that the problem is in the method itself and not the call.
    It could be some odd VM problem so trying a different version of 1.4.2 might help (but in of itself would not eliminate the possibility that you have a memory problem.)

  • Arrays pass by reference?

    Hi,
    Just wondering in Java when you send a method an array, does it send a copy of the array, or a reference to the original array?

    please
    don't start that holy war up again!Oh come on, let's! It'll pass the time untilFriday
    quicker. ;)<devils-advocate>
    but surely if I'm not passing an object itself,but
    a
    reference to the object, then that's
    pass-by-reference
    Oh, do shutup. :-P
    Pass a reference != pass
    by reference.don't give me semantics. the mechanism by which I'm
    passing the object is as a reference ergo,
    it's passed, by it's reference. if it was
    pass-by-value, the object itself would be copied and
    passed, but we know it's not, so it's
    pass-by-referencePlease tell me you're kidding. And if you are, pleaes stop, lest the OP gets confused.

  • PL/SQL array passed to SQL IN

    Hi,
    I have a PL/SQL array which type is defined like this:
    create or replace type type_id_array as table of number(6, 3);
    then i create a variable and initilaize:
    var_1 type_id_array;
    var_1 := .....
    then i have a select statement.
    select * from table t where t.id in(var_1)
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?
    Thanks

    user610868 wrote:
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?SQL supports set commands specifically for arrays (in addition to the using the TABLE() method mentioned). For example:
    SQL> create or replace type TNumbers is table of number;
      2  /
    Type created.
    SQL>
    SQL> declare
      2          numList TNumbers;
      3          cnt     integer;
      4  begin
      5          numList := new TNumbers(1,2,3,4,5,6,7);
      6          select
      7                  count(*) into cnt
      8          from    user_objects
      9          where   TNumbers(object_id) member of numList;
    10          DBMS_OUTPUT.put_line( 'cnt='||cnt );
    11  end;
    12  /
    cnt=0
    PL/SQL procedure successfully completed.Obviously there are performance considerations when using arrays/collections in SQL. So before choosing a method, evaluate the performance.

  • BASH: iterate  through an array  passed in

    I have the following function that does not iterate through the array I want to be able to do some maanipulation on each element in the array[@] Any ideas whats wrong with the below for loop ????
    function foo() {
    name =$1
    array=( "$2" )
    for i in `seq 0 $(( ${#array[@]} - 1 ))`; do
    echo "$i: ${array}"
    echo "./prog $name ${array[i]}"
    done
    NAME ="BLAH"
    arrayP+=("TEST") ;
    arrayP+=("TESTB")
    arrayP+=("TESTC")
    foo $NAME "${arrayP[@]}"
    Edited by: user618557 on 19-May-2011 12:57

    Your code needs a small correction in order to work, at least when I tried:
    foo "${name}" "${array[@]}"
    should read
    foo "${name}" "${arrayP[@]}"However, I would use a different approach, which is perhaps also not as ugly:
    #!/bin/bash
    foo() {
       name="$1"
       for i in $2; do
       set -- $i
       echo "$name $*"
    done
    name="BLAH"
    arrayP+=("TEST")
    arrayP+=("TESTB")
    arrayP+=("TESTC")
    foo "$name" "${arrayP[*]}"gives:
    $ ./allarray
    BLAH TEST
    BLAH TESTB
    BLAH TESTCI used this also in the previous thread BASH 3.2.25 multidemsional arrays which however, apparently wasn't helpful.

  • Pixel intensity array, pass or fail

    I am having issues creating a VI that inspects the pixtel intesity within a given rectangle.
    One of the problems I have is that in between the solar cells (see picture attached) there is a lead that appears black under SWIR imaging. So I would need two rectangles to inspect the system, and I havent been able to succeed in creating such program.
    The second issue I have, I need a VI that checks within the rectangle(s) region specified all the pixel intensity. If there is an amount of pixels that is not within that region (broken solar cell), assign a fail inspection. (see attachement).
    Any help would be appreciated
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    good-broken.jpg ‏61 KB

    You should look into the Histogram tool.  I've attached a VI as an example.  It doesn't solve your ROI question, but it shows how to cut out the area as a rectangle.
    Here's an image of the results of the histogram.  You could use the "Mean Value" as a measure of good/bad.
    Attachments:
    Histogram.vi ‏384 KB
    broke.jpg ‏17 KB
    good.jpg ‏15 KB

  • Passing values from method array to class array

    HELP!! Plz excuse any ignorance. Am a noob and have created an array within my class. I then try to alter those array values from inside one of the classes methods. When I try to access the new values from the class array, they don't exist. I think it's a duration/scope issue and am struggling to get around it. This is the only way I can implement the task required and would appreciate any advice you can thorw. cheers in advance.. =~D

    I suspect that you're altering an array passed as a parameter, rather than array that's a field of the instance, but as you didn't post any of your code, that can only be a guess.

  • How to pass byte array / binary data to a webservice as parameter in osb

    i have a webservice that has a byte array input parameter. i tried to use this WS in a message flow via service-callout. the problem i encountered is the following: since webservice call by using service-callout requires you to use an xml input as part of soap message, i insert both of $body/ctx:binary-content and $body/ctx:binary-content/@ref variables individually into this xml-message to pass binary-data to WS. When i debug the code, i see that it make calls to WS with $body/ctx:binary-content/@ref parameter, but the byte array passed is empty(not NULL)...
    note: i tried java-callut instead of service-called and used $body/ctx:binary-content as input parameter it worked. i think, this is because java-callout doesnt need an xml input and enable to take variables as is...
    can anybody help me to solve the problem with service-callout please?
    here is the input i use to call ws with service-callout method...
    <iso2Xml xmlns="http://www.mycompany.com.tr">
    <request>{$body/ctx:binary-content/@ref}</request>
    </iso2Xml>
    and this is my WS's signature:
    @WebMethod
    public String iso2Xml(byte[] request)

    Hi
    See this thread
    /message/2187817#2187817 [original link is broken]
    Kind Regards
    Mukesh

  • Passing Array From Subreport to Main Report then Summing

    Hi,
    I am having troble passing an array from a sub report to the main repport.  I have managed to create the array, pass it and display it in the main report, however the first value of the array is displayed twice.  Here is the  formulae I have used:
    In the sub report:
    whileprintingrecords;
    shared stringvar str;
    str:=str{@value}","
    In the main report:
    whileprintingrecords;
    shared stringvar str;
    stringvar array arr;
    arr:=split(str,",");
    join(arr,",")
    Also, when I have managed to resolve the problem of the first value printing twice, I hope to change the array back to a number array and sum all of the values together.  I'm not too sure how to do this either.
    I hope you can help.
    Julie

    Ummm... Isn't Join(Split(str,","), ",") = str?  Why bother with the two extra lines of code?  Also, are you sure the subreport isn't creating the "duplicate first value"?  (I.e.  The data has the same value on two records, so it's being added twice?)
    Also if you're looking for the sum, why not create another shared variable and sum the value in the subreport as you're building the array (assuming you need the array for other purposes)?
    HTH,
    Carl

  • Array required, passing as an arguement to contructor which wants an array

    Hello again, can you help me with this?
    here is the error
    C:\jDevl\GameTest.java:19: array required, but Lot649.Ticket1 found
              lotto[0] = new Ticket1(1,2,12,1982, 3, 11, 12, 14, 41, 43, 13);
    ^
    C:\jDevl\GameTest.java:20: array required, but Lot649.Ticket1 found
              lotto[1] = new Ticket1(2,2,19,1982, 8, 33, 36, 37, 39, 41, 9);
    ^
    C:\jDevl\GameTest.java:21: array required, but Lot649.Ticket1 found
              lotto[2] = new Ticket1(3,2,26,1982, 1, 6, 23, 24, 27, 39, 34);
    ^
    HERE IS THE GAMETEST CODE, I BELIEVE THE PROBLEM IS WITH MY CONSTRUCTOR
    IN THE TICKET CLASS...
    public class GameTest{
         public static void main( String args[]){
              String result = "";
              //fill the lottery array with 5 ticket objects
              Ticket1 lotto = new Ticket1();
              Ticket1 t = new Ticket1();
                                  //recNo,mmddyr, n1, n2, n3, n4, n5, n6, n7}
              lotto[0] = new Ticket1(1,2,12,1982, 3, 11, 12, 14, 41, 43, 13);
              lotto[1] = new Ticket1(2,2,19,1982, 8, 33, 36, 37, 39, 41, 9);
              lotto[2] = new Ticket1(3,2,26,1982, 1, 6, 23, 24, 27, 39, 34);
              lotto[3] = new Ticket1(4,3,3,1982, 3, 9, 10, 13, 20, 43, 34);
              lotto[4] = new Ticket1(5,3,3,1982, 3, 11, 12, 14, 41, 43, 14);HERE IS THE TICKET CLASS CODE... dang those arrays, i believe i have messed up somehow with the arrays passing as args.
    public class Ticket1{
         private int recNum;
         private int mm;
         private int dd;
         private int yy;
         private int nArray[] = new int[7];
         public Ticket1(){
                        recNum = 0;
                        //drawDate = dDay.getDate();
                        //Date dD = new Date();
                        //drawDate = dDay.getDate();
                        mm = 1;
                        dd = 1;
                        yy = 1900;
                        nArray[0] = 0;
                        nArray[1] = 0;
                        nArray[2] = 0;
                        nArray[3] = 0;
                        nArray[4] = 0;
                        nArray[5] = 0;
                        nArray[6] = 0;
         }//end of constructor
         public Ticket1( int rec, int mon, int day, int year, int n1, int n2,
                         int n3, int n4, int n5, int n6, int n7){
              recNum = rec;
              //drawDate = dDay.getDate();
              //Date dD = new Date();
              //drawDate = dDay.getDate();
              mm = mon;
              dd = day;
              yy = year;
              nArray[0] = checkNum(n1);
              nArray[1] = checkNum(n2);
              nArray[2] = checkNum(n3);
              nArray[3] = checkNum(n4);
              nArray[4] = checkNum(n5);
              nArray[5] = checkNum(n6);
              nArray[6] = checkNum(n7);
         }//end of ticket constructor
         public Ticket1( int recA, int monA, int dayA, int yearA, int arrayName[] ){
              recNum = recA;
              mm = monA;
              dd = dayA;
              yy = yearA;
              nArray[0] = arrayName[0];
              nArray[1] = arrayName[1];
              nArray[2] = arrayName[2];
              nArray[3] = arrayName[3];
              nArray[4] = arrayName[4];
              nArray[5] = arrayName[5];
              nArray[6] = arrayName[6];
         }//end of Ticket1 constructor

    Ticket1 lotto = new Ticket1();lotto is not delcare as an array and you wants it to act like an array?
    lotto[0] = new Ticket1(1,2,12,1982, 3, 11, 12, 14, 41, 43, 13);
    lotto[1] = new Ticket1(2,2,19,1982, 8, 33, 36, 37, 39, 41, 9);you should do :
    Ticket1 lotto[] = new Ticket1[5];

  • How can i pass array as parameter

    I want to pass user input array to a separate class and do mathematical
    operations . I want to know how to pass thedata entred by user to another class method or same class separate method

    I want to pass user input array to a separate class
    and do mathematical
    operations . I want to know how to pass thedata
    entred by user to another class method or same class
    separate methodThis is several tasks. Break the problem down into managable parts.
    If by "input array" you mean the keyboard you have to
    -capture the input stream from the keyboard in a string or stringbuffer
    -parse the string or stringbuffer into pieces which can be converted to numbers
    -put the numbers into an array
    -pass the array to your class (or method) which operates on it

  • Passing array to DLL

    Hi -
    I need to interface with a DLL. I can communicate fine with most of the functions, but I can't figure out how to configure Call Library Function for "GPIO_Init". Can anyone with more experience help me out? I've attached the header, and also the manual - it's section 3.8.1 (page 37)
    Many thanks,
    Jon.
    Solved!
    Go to Solution.
    Attachments:
    LibFT4222.h ‏11 KB
    AN_329_User_Guide_for_LibFT4222.pdf ‏748 KB

    See this recent thread with approximately the same question: http://forums.ni.com/t5/LabVIEW/FTDI-FT4222-DLL-calling/m-p/3146709
    In this case, you pass a LabVIEW array and configure the array parameter as an array, passed by array data pointer.

Maybe you are looking for

  • Word 2010 table rendered reduced, upside down and backwards on conversion to pdf

    We have a Word 2010 document that includes a table, header and footer and a title paragraph with a border. When we convert this to pdf using Word's Acrobat -> Create PDF function, we get this (converting via Print -> Adobe PDF works fine however). He

  • Error signing in Acrobat 7 pro

    I keep getting the following error when signing document... Unknown error Support Information: CSigDict-1812 Some help? Also, I cannot get it to remember my Digital ID after I close Acrobat... and YES, I click Always Use EVERY time.

  • Question on buying a phone outright to keep my unlimited Verizon contract.

    Howdy I have a contract that I've had for about 8+ years its totally unlimited. My old DroidX is on it's last leg. Verizon wants me to buy a new phone and contract, limiting my limits. I seldom reach their minimum basic account, they say I don't need

  • Data into the Tables.

    Hi, I thought of putting my question in the forum. The question is, when we are doing some changes in the forms applications in oracle apps and save the data, is there anyway that i can know to how many and which tables the data is getting saved to??

  • RRMX/SSO not working with Win7/GUI 7.2

    Dear all, I'm testing the useability of our BW system with new Windows 7 and SAP GUI version 7.2. The only way of launching BEx analyzer is via RRMX or portal (using single sign-on) but this is not working. Once i trigger RRMX, Excel 2007 is opened (