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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • 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.)

  • How can I pass an empty array to a parameter of type PLSQLAssociativeArray

    How can I pass an empty array to a parameter of type PLSQLAssociativeArray in VB? I defined the parameter like this
    Dim myArray() as String = new String() {}
    Dim myPara as new Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray
    myPara = 0
    myPara.Value = myArray
    When I execute my stored procedure giving the above parameter, I got error saying OracleParameter.Value is invalid.
    I have tried to give it the DBNull.Value, but it doesn't work either.
    Note: everything works fine as long as myArray has some item in there. I just wonder how I can make it works in case I have nothing.
    Thank you,

    How can I pass an empty array to a parameter of type PLSQLAssociativeArray in VB? I defined the parameter like this
    Dim myArray() as String = new String() {}
    Dim myPara as new Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray
    myPara = 0
    myPara.Value = myArray
    When I execute my stored procedure giving the above parameter, I got error saying OracleParameter.Value is invalid.
    I have tried to give it the DBNull.Value, but it doesn't work either.
    Note: everything works fine as long as myArray has some item in there. I just wonder how I can make it works in case I have nothing.
    Thank you,

  • Error While calling stored procedure with array

    I am getting following error
    java.sql.SQLException: Fail to construct descriptor: Invalid arguments
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:829)
    at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:85)
    at oracle.sql.STRUCT.toSTRUCT(STRUCT.java:322)
    at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:253)
    at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:296)
    at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:137)
    at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:750)
    while executing following code
    com.brocade.wwn.params.AuthParams ap = new com.brocade.wwn.params.AuthParams();
    ap.setAuthKey("1");
    ap.setAuthValue("1.1");
    com.brocade.wwn.params.AuthParams ap1 = new com.brocade.wwn.params.AuthParams();
    ap.setAuthKey("11");
    ap.setAuthValue("1.11");
    //com.brocade.wwn.params.AuthParams[] arrAP = new com.brocade.wwn.params.AuthParams[1];
    //Object[] arrAP = new Object[1];
    //arrAP[0] = ap;
    com.brocade.wwn.params.AuthParams[] arrAP = {ap,ap1};
    System.out.println(" >>> Creating Array Descriptor .... ");
    oracle.sql.ArrayDescriptor arraydesc =
    oracle.sql.ArrayDescriptor.createDescriptor("WWP.AUTH_ENTRIES", conn);
    System.out.println (" ----> " + arraydesc.getBaseName());
    System.out.println (" ----> " + arraydesc.getName());
    System.out.println (" ----> " + arraydesc.getSQLName());
    System.out.println (" ----> " + arraydesc.getSchemaName());
    System.out.println (" ----> " + arraydesc.getTypeName());
    System.out.println (" ----> " + arraydesc.getMaxLength());
    System.out.println (" ----> " + arraydesc.getArrayType());
    System.out.println ( arraydesc.TYPE_VARRAY + " : " + arraydesc.TYPE_NESTED_TABLE );
    // Object[] tObj = arraydesc.toArray(arrAP);
    //tObj = new String[2];
    //tObj[0] = "sdaf";
    //tObj[1] = "sdaf1";
    // tObj[0] = ap;
    System.out.println(" >>> Array Descriptor Created .... ");
    oracle.sql.ARRAY array = new oracle.sql.ARRAY(arraydesc, conn, arrAP);
    My database is Oracle 8i and I am using oracle 9i thin drivers.
    Can anybody help me on this ....
    thanks

    I am trying to pass parameter to test my procedure but it is giving this error : ORA-06531: Reference to uninitialized collection
    ORA-06512: at line 12
    Here is example for my test procedure:
    declare
    v_session_id_tab SESSION_ID_TAB_TYPE;
    v_service_type_tab SERVICE_TYPE_TAB_TYPE ;
    v_service_location_tab SERVICE_LOCATION_TAB_TYPE ;
    v_service_call_name_tab SERVICE_CALL_NAME_TAB_TYPE;
    v_service_call_start_time_tab SERVICE_CALL_ST_TAB_TYPE;
    v_service_call_end_time_tab SERVICE_CALL_ET_TAB_TYPE;
    v_service_call_duration_tab SERVICE_CALL_DUR_TAB_TYPE;
    v_status_tab STATUS_TAB_TYPE;
    v_notes_tab NOTES_TAB_TYPE;
    begin
    v_session_id_tab(1) := 1;
    v_service_type_tab(1) := 'db';
    v_service_location_tab(1) := 'local';
    v_service_call_name_tab(1) := 'Name of call';
    v_service_call_start_time_tab(1) := SYSDATE;
    v_service_call_end_time_tab(1) := SYSDATE;
    v_service_call_duration_tab(1) := 100;
    v_status_tab(1) := 'Z';
    v_notes_tab(1) := 'NOTES';
    BULK_INSERTS (v_session_id_tab,v_service_type_tab, v_service_location_tab,v_service_call_name_tab,v_service_call_start_time_tab,v_service_call_end_time_tab,
    v_service_call_duration_tab, v_status_tab, v_notes_tab);
    end;
    I declare all types at schema level.
    Please give your comments.
    Thank you

  • How to pass value in array to another procedure?

    Hello.
    I have created application by Developer form9i.
    And I have some problem about passing value in array to another procedure.
    My code is :
    PROCEDURE p_add_array (col_no in number,
    col_val in varchar2) IS     
    type xrecord is record(col number,vcol varchar2(1000));
    xrec xrecord;
    type varraytype is varying array(42) of xrecord;     
    xvartab varraytype := varraytype();
    alert number;
    BEGIN
    set_application_property(cursor_style,'busy');
    xrec.col := col_no;
    xrec.vcol := col_val;
    xvartab.extend(1);
    xvartab(col) := xrec;
    EXCEPTION
    when others then
    set_application_property(cursor_style,'default');
    alert := f_show_alert('!Error ORA-'||
    to_char(DBMS_ERROR_CODE)||' '||
    substr(DBMS_ERROR_TEXT,1,240),
    'al_stop');          
    END;
    And I want to have
    PROCEDURE p_print_arrey is
    BEGIN
    END;
    So how to bring value of xvartab( ) in p_add_array to use in p_print_array?
    Anybody please help me solve this ploblem.

    Hi,
    Instead of declaring the array locally within the procedure (i.e. p_add_array), define it in the package specification (i.e. Under Program Units).
    -- Shailender Mehta --

  • Passing pl/sql array to function

    Hi,
    I have a function which takes an array:
    create or replace
    FUNCTION execute_tests(
    leg_keys IN type_leg_key_array)
    RETURN BOOLEAN
    IS
    BEGIN
    leg_key_array is this:
    create or replace
    TYPE type_leg_key_array AS TABLE OF NUMBER(6, 3);
    I would like to test this funtion by passing it some array:
    DECLARE
    LEG_KEYS DEV_SWA30PRE.TYPE_LEG_KEY_ARRAY;
    V_RETURN BOOLEAN;
    BEGIN
    -- LEG_KEYS := NULL;
    v_Return := EXECUTE_TESTS(LEG_KEYS);
    END;
    What is wrong with the snippet above?
    Thanks

    Hi,
    user610868 wrote:
    Hi,
    I have a function which takes an array:
    create or replace
    FUNCTION execute_tests(
    leg_keys IN type_leg_key_array)
    RETURN BOOLEAN
    IS
    BEGIN
    leg_key_array is this:
    create or replace
    TYPE type_leg_key_array AS TABLE OF NUMBER(6, 3);
    I would like to test this funtion by passing it some array:
    DECLARE
    LEG_KEYS DEV_SWA30PRE.TYPE_LEG_KEY_ARRAY;
    V_RETURN BOOLEAN;
    BEGIN
    -- LEG_KEYS := NULL;
    v_Return := EXECUTE_TESTS(LEG_KEYS);
    END;
    What is wrong with the snippet above?Why do you think anything is wrong? Are you getting an error message? Post the complete error message, including line numbers. Does the error occur when you create the type, when you create the function, when you call the function, or someplace else?
    The only errors I see are probably due to how you chose to post it. For example, there is no RETURN or END statement in execute_tests.
    Did you create the type before trying to use it in the function?
    What is DEV_SWA30PRE? Is that a schema? Does that schema also contain the fucntion? Is that who is running the anonymous block? If there are other schemas involved, what are they? What are they doing? What privileges do they have on the type or the function?
    Post a complete test script that people can run to re-create the problem and test their ideas.

  • Passing a Variant array to ArrayToImage Function

    Hi,
    I need help passing a Variant array to the ArrayToImage function in the NI Vision library.
    I have no problems using the ImageToArray function - but when going back to the CWIMAQImage type the application throws an exception.
    Are there any code samples for doing this?
    Thanks!

    Hello,
    Thank you for posting to the NI forums! Try calling the ImageToArray function then immediately passing the resultant array back to ArrayToImage. That will determine whether the ArrayToImage function is causing the error, or the array that is passed into it. Can you post a small sample of how you call the ArrayToImage function and the errors that are thrown?
    Thanks,
    Maclean G.
    Applications Engineering
    National Instruments

  • Passing LrPhotos in arrays

    I know in the table-based world of Lua this is probably klutzy, but hear me out. In one part of my code I am creating an Array of Arrays containing information
    about some LrPhotos as well (for good measure) as the actual LrPhotos, and I'm putting it in dialogData.catalog, which is a global property table produced by LrBinding.makePropertyTable.  Here is the code that creates that Array of Arrays:
             --photos is an array of LrPhotos:        for i=1, #photos do            local photo=photos[i]            local path= photo:getRawMetadata( 'path' )            local dateTimeDigitized= photo:getRawMetadata( 'dateTimeDigitized' )            local uuid= photo:getRawMetadata( 'uuid' )             dialogData.catalog[#dialogData.catalog+1]= {path,dateTimeDigitized, kwImageId, uuid, photo}          end
    None of the items in the inner array are "keyed" or whatever that is called in Lua, and that doesn't seem to be a problem later when I retrieve the data. I get the path, the dateTimeDigitized, and kwImageId (which is later populated with data from a SQLite database).  But no matter what I do, when I try to use the photos (the fifth item in the inner array) later on, it comes back as nil.   There doesn't seem to be any way to use photo placed in an array this way. What am I doing wrong?  This is driving me insane.

    i can confirm that dialogData.catalog[i][5] is an LrPhoto because when i do something like myLogger:trace(tostring(dialogData.catalog[i][5]))
    i get
    LrPhoto( id "26" )
    but when i try to do something like
    if myPhoto~=nil then                 local myPath =myPhoto:getRawMetadata( 'path' )                  myLogger:trace( "mypath"  ..myPath  ) end
    the code never gets beyond the
    local myPath =myPhoto:getRawMetadata( 'path' ) 
    line. it's as if the getRawMetadata method is impossible and is throwing an error, though not one i ever see.
    thanks for the tip about the debugging tools. debugging in the SDK is a royal b&iota;&tau;ch.

  • Passing empty Associative Array

    I have a sProc that takes a number and then an optional plsql table of numbers.
    I cannot figure out how to pass the empty array to Oracle. I set the param size to 0 and try to set the value to null but it throws an exception if it is null or system.dbnull.
    I tried the suggestion of passing an array of size one but it passes 0 to my sproc. My sproc is doing an PLSQLTable.Count check to process the list so it needs to have count = 0;
    Any ideas?
    thx
    jack
    BTW - There is a similar thread here: Passing empty Associative Array

    We are having the same problem, but the suggested work-around mentioned above will not work for us. In our case, our stored procedure has multiple TABLE parameters that it expects to have the same length.
    For example, a stored procedure that is used to insert multiple records in to an "Addresses" table. Each parameter in the stored procedure represents a single element in the address (line1, line2, line3, city, state, zip code). Here's a rough facsimile of what we're working with:
    TYPE tElement IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
    PROCEDURE insAddresses ( pLine1 tElement,
                   pLine2     tElement,
                   pLine3     tElement,
                   pCity     tElement,
                   pState     tElement,
                   pZipCode tElement )
    IS
    BEGIN
    FOR i IN pLine1.FIRST..pLine1.LAST
    LOOP
    INSERT INTO addresses
    (line1, line2, line3,
    city, state, zipcode)
    VALUES
    (pLine1(i), pLine2(i), pLine3(i),
    pCity(i), pState(i), ZipCode(i));
    END LOOP;
    END insAddresses
    In this case, each array passed into the procedure must have the same length. Unfortunately, not all addresses have values for Line2 or Line3, so more often than not, those arrays are empty. Even though they had been declared with the same length as the Line1 array, the values are all null. When Oracle tries to read from those empty arrays, it throws the following error, "ORA-01403: no data found".
    This is how we are passing the parameter to Oracle from C#:
    public void AddInputParameter( string pName, string[] pValue)
    OracleParameter param = mCom.Parameters.Add(pName,OracleDbType.Varchar2);
         param.Direction = ParameterDirection.Input;
         param.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
         param.Value = pValue;     
         param.Size = pValue.Length;

  • 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.

  • Error while retrieving data from an ARRAY resultset

    We hava an Oracle stroed procedure which has a table type as its OUT parameter and where the data is being entered into. This data requries to be returned to the Java client through a JDBC connection. We have used the OracleTypes' ARRAY object for this. We are facing errors when retieving data from the ARRAY resultset
    The Oracle Package
    ----I created a table type called "PlSqlTable":
    CREATE OR REPLACE TYPE PlSqlTable IS TABLE OF VARCHAR2(20);
    ----I defined this as the out parameter for my procedure :
    PROCEDURE testSQL
    arrayOutID OUT PlSqlTable
    Then populated the object :
    arrayOutID := PlSqlTable();
    arrayOutID.extend(4);
    arrayOutID(1):= 'Hello';
    arrayOutID(2) := 'Test';
    arrayOutID(3) := 'Ora';
    ----The procedure executes fine - all debug statements are printed ----right till the end of execution.
    The Java class
    ----Here is how I have defined the parameters :
    OracleCallableStatement stmnt = (OracleCallableStatement)connection.prepareCall("begin testSQL(?);end;");
    stmnt.registerOutParameter(2,OracleTypes.ARRAY,"PLSQLTABLE");
    System.out.println("Executing..");
    stmnt.execute();
    System.out.println("Executed..");
    ARRAY outArray = stmnt.getARRAY(1);
    System.out.println("Got array");
    ResultSet rset = outArray.getResultSet();
    System.out.println("Got Resultset..");
    int i = 1;
    while(rset.next()){
    System.out.println("VALUE : " + rset.getString(i));
    i = i+1;
    ----On execution, the debug messages display :
    Executing..
    Executed..
    Got array
    Got Resultset..
    VALUE : 1
    VALUE : Test
    ERROR : java.sql.SQLException: Invalid column index
    ----But I have populated upto 3 values in th e procedure. Then why this error ?
    PLLLEEEASE help me out on this.
    Thanks, Sathya

    haven't worked with db arrays but I think your problem is here:int i = 1;
    while(rset.next()){
         System.out.println("VALUE : " + rset.getString(i));
         i = i+1;
    }In the first loop you are retrieving the value from column 1(rs.getString(1)), which is OK, but in the second loop, you are trying to retrieve a value from the second column(rs.getString(2)) which doesn't exist. Try this code which only reads from column1:
    while(rset.next()){
         System.out.println("VALUE : " + rset.getString(1));
    }Jamie

  • How to pass a multidimensional array to an Oracle procedure?

    How can I pass a multidimensional array to oracle array?
    Thanx in anticipation,

    Look in to passing user defined type back and forth to Oracle. Any type that oracle supports, you can constract on the java side and send it across. Look into the SQLData class.

  • Error occurred while accessing the safe array

    I am using HFM 931. One of the users are getting this error.
    Error occurred while accessing the safe array. Error Reference Number: {9F7B34B7-4698-48B3-9F2B-A89715675639}
    Num: 0x80040211;Type: 1;DTime: 20/10/2009 14:34:08;Svr: UK-SUT-TD-FWEB1;File: CHFMwDataGrid.cpp;Line: 5889;
    Can you please help me fix this issue?
    Thanks
    Hemanth
    Edited by: HemanthK on Nov 6, 2009 10:00 AM

    there are many different causes for safe array error messages.
    i would advise to contact support before looking for help for safe array messages in the forums. if you open an SR be sure to attach HsvEventLog.log file from all application servers in the environment so that the support engineer can check them.
    if the message it is restricted to one specific user it may be related to that users preferences / POV settings in the appname_USERPARAMS database table. you may like to try to remove the userparams for that specific user from the table. before you do this you need to make sure that HFM (all HFM related processes and services) is stopped on all servers in the environment and that you have a recent backup of the HFM database.
    also please make sure you have patched your 9.3.1 HFM to 9.3.1 SP 4 + SF's 9.3.1.4.01, 9.3.1.4.03 and 9.3.1.4.05. it is recommended that all HFM 9.3.1 administrators have applied all of the above Service Packs and Service Fixes.

  • Fast way to find the number of non-zero terms in an array or image

    I am trying to use the Standard Deviation PtbyPt Vi.  It takes in a series of points, can be reset when beginning the calculation.  There is also an input for sample size.  I am calculating some statistics on an array...and would only  to include like the non-zero elements that are  in the sample. 
    Is there a quick way to look at an array and find the number of non-zero elements?
    Thanks.
    Solved!
    Go to Solution.

    GerdW wrote:
    - for big arrays this may lead to "out of memory" problems because of creation of data copies
    Here's a quick rundown on memory allocations based on the algorithm.
    (case 1&3)
    If you do the "!=0, ?1:0, I32, sum" shuffle, each step needs to allocate a new array, so if the input array is DBL and uses N amount of memory, we need 7N/8 more memory.
    (Total of 15N/8, or 13N/8 if we don't need the I32, but in this case the array are too small to worry about anything )
    The nice thing is that it works for any array dimensionality (1D, 2D, 5D, etc...)
    (Case 2&5)
    If you do the summing in a shift register, No additional array memory is needed. Unfortunately, the code needs to be changed by adding an extra FOR loop for each dimension (see case 5 for 2D inputs).
    (Case 4)
    If we reshape the N-D array to a 1D array, we need to create a second copy, so the memory usage is about twice. This also works for any dimension.
    In real life, and if memory is a potential issue, you should always do some benchmarks.
    Often, the issues are more complex, so this is just a quick summary.
    Message Edited by altenbach on 10-23-2008 11:59 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    CountNonZero.PNG ‏29 KB

  • Problem passing oracle.sql.ARRAY to Oracle

    I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
    Here is my code:
    PreparedStatement stmt = null;
    String strArray[] = { "1,2,3,4,5" };
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    //encounter Exception on the line below.
    ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
    String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
    stmt = dbConnection.prepareStatement(queryStr);
    stmt.setArray( 1, array_to_pass );
    stmt.execute();
    I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
    MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
    Really frustrated searching through the forums for the whole day,
    Thanks,

    Try this if you are at weblogic 8.1:
    Connection con = getConnectionFromDataSource();
    Connection vendorConnection = ((WLConnection)con).getVendorConnection();
    // use direct oracle connection.
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    vendorConnection.close();
    Beware that you should be very careful as you are going to use a direct vendor
    connection.
    The better aproach is to pass the string array as a delimited string to your storad
    procedure and parse it in the SP - then you don't have to mess up with vendor-specific
    handling.
    Hope this helps.
    Regards,
    Slava Imeshev
    "Daddy Daddy" <[email protected]> wrote in message news:24349835.1097143668312.JavaMail.root@jserv5...
    I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
    Here is my code:
    PreparedStatement stmt = null;
    String strArray[] = { "1,2,3,4,5" };
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    //encounter Exception on the line below.
    ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
    String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
    stmt = dbConnection.prepareStatement(queryStr);
    stmt.setArray( 1, array_to_pass );
    stmt.execute();
    I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
    MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
    Really frustrated searching through the forums for the whole day,
    Thanks,

Maybe you are looking for

  • Triggering Process chain based on execution of R3 job and Process Chain

    Hi All, I need your help in arriving at a solution for a reqirement. Scenario is., I need to trigger a process chain B based on successful execution of Process chain A and an R3 job. If both conditions(Completion of R3 job and Process Chain A) are me

  • Adobe Acrobat Reader Standard 9

    Hello! A long time ago i purchased Acrobat 9 Standard, and I'm having trouble finding a download link to the installer. Could anyone give me a hint? I'm in phone queue atm, but it seems like there's nobody to respond on this number. So a link would b

  • I made a folder how do I put a PDF in it?

    See above

  • Oracle 11g Active Data Guard and SAP R3

    Hi All, I have a query regarding Oracle 11g Active Data Guard and SAP R3. Does the Oracle 11g R1/R2 Active Data guard feature supported with SAP R3? I appreciate your help to provide any link or document for the same. Thanks, Vihang

  • I want to open files from a link but I don't want to save it

    Hello, I use firefox mostly as a browser and everytime I click on a link on the web to open a file that file opens but it also goes to my download folder. The dialog box opens and asks do I want to save or open and even when I put open it saves to my