JNI and multidimentional arrays

Hi
I'm dealing with C functions that used multidimentional arrays like tab[10][200]
I don't know how to get them from my JAVA code using
GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
or
GetIntArrayRegion(JNIEnv *env, jobjectArray array, start, lenght ...)
I seems that it is working only with one dimentional arrays ?
Am I right ?
Does anybody knows how to do with multidimentional ?
Thank you !

I'm dealing with C functions that used
multidimentional arrays like tab[10][200]Multidimensional arrays are awkward to deal with.
A multidimensional array in Java is an array of arrays. In effect they are like 'ragged' arrays in C, not like 'rectangular' ones. There is no way to get a 2-dimensional primitive array that contains the contents of a 2-dimensional Java array. In fact there is no way to directly access elements of a 2-dimensional Java array at all.
In order to navigate around in a multidimensional Java array from native code, let's say you have int[10][15] and you want to get the element at [5][8]. You must use GetObjectArrayElement(env, arrayObject, 5) and this will give you the 15-element int array. Now you can use GetIntArrayRegion() or whatever to retrieve those ints. If it had been an array of objects instead of primitives then you would have to use GetObjectArrayElement on the "inner" array as well, of course.
So your only real choice is to use a for loop. The outer for loop gets the array of primitives and then you can use GetIntArrayRegion and memcpy() etc. to copy that array into the appropriate row of your C array.
If you had a 3-dimensional array you'd have to repeat this process because the first time through it would return a 2-dimensional array.

Similar Messages

  • JNI and huge Array

    Hi,
    I need to transfer nearly 120k buffer to Native C++ code and the same data back to JAVA.
    I like to know how this array is transfered from Java to C++ and C++ to Java?
    Can I pass the reference from Java to C++?
    Thanks in advance
    Raja

    Do you need to use the data in java? Then you have to do the regular jni array stuff.
    If you don't use it, then just have java keep a pointer - put the pointer into a java long and re-extract when you need it again.

  • JNI and multidimensional arrays

    Hi
    the last days i spent searching information on how to process larger multidimensional primitive arrays ([5][300][300]) with JNI but i failed to find stringent proof for it is possible or not. Maybe somebody her can help:
    i want to pass a 3D array of ints to a c-function and do excessive manipulation there, then pass the array back. Possible? where can i find sources on that?
    Thanks for any help
    Shin

    Yes.. this is quite possible. To take your example, you would access foo[1][2][3] like this:jojbectArray middleArray = static_cast<jobjectArray>( env->GetObectArrayElement( fooArray, 1 ) );
    jintArray endArray = static_cast<jobjectArray>( env->GetObjectArrayElement( middleArray, 2 ) );
    int element = env->GetIntArrayElement( endArray, 3 );God bless,
    -Toby Reyelts
    Check out the free, open-source JNI toolkit, Jace - http://jace.reyelts.com/jace

  • Multidimentional array - this is so weird!

    Hi,
    This is so weird! I read a data file into a multidimentional array, like this:
         for (int index=0;index < numLines;index++) {
              line = fileInput.readLine();
              fields = line.split("\t");
              for (int i=0; i<5; i++){
                   dataset[index] = fields[i];
                   textArea.append(dataset[index][i] + "\t");
              textArea.append("\n");
    Say the data file is like this:
    apple 3 sweet cool buy
    orange 2 sore hot notbuy
    apple 2 sore cool notbuy
    And i ended up with a multidimentional array: dataset[11][5]
    Then i call a method from another class to generate decision tree like this:
         Node node = new Node(ds2, " ");
         rules = node.getRules();
         System.out.println(rules);
    Then i got incorrect decision rules.
    With every other single code the same, if I create the multidimentional array manually like this:
         dataset[0][0] = "apple";      
         dataset[0][1] = "3";      
         dataset[0][2] = "sweet";      
         dataset[0][3] = "cool";      
         dataset[0][4] = "buy";     // row #1
         dataset[1][0] = "orange";
         dataset[1][1] = "2";      
         dataset[1][2] = "sore";      
         dataset[1][3] = "hot";           
         dataset[1][4] = "notbuy";     // row #2 ...
    Then it will work and generate the correct rule.
    My question is, how is the multidimentional array generate by reading a file different from generate manually?
    Thanks!

    It's not that you're reading a file per se.
    Probably you're using split incorrectly.
    In the loop where you're setting data[index] [ i ], print out each element as it's set, surrounding it with quotes so you can see if there are spaces or something dataset[index] = fields[i];
    System.out.println("'" + dataset[index][i] + "'");
    Also, using index and i as outer and inner loop variables is confusing and not descriptive.
    When you post code, please use [[i]code] and [/code] tags as described in [url=http://forum.java.sun.com/features.jsp#Formatting][u]Formatting Help[/u][/url] on the message entry page. It makes it much easier to read.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Multidimentional Array

    String str[][] = new String[3][3];
    System.out.println("str[0] "+str[0]); prints
    str[0] [Ljava.lang.String;@82ba41[/i] in the console.
    what does str[0] refer to? first row but which column.....and from where does str[0] take the output.(i mean the output displayed)

    Hello.
    Generally in Java multidimentional array is array of arrays.
    So if You define a
    String str[][] = new String[3][3];You have an array with dimension 3 which contains 3 arrays of strings (Each of this arrays can has different length).
    Every Java object (and Your array is object too )has method toString() which defines what this object will ouputted, when it called as String.
    Hope this helps.
    Maks

  • JVM Crash When Using JNI and COM

    I'm trying to call a DLL compiled from VB6 source code that I do not have access to. The VB6 code simply retrieves data from a DB2 database using ADO and my client code grabs that data and marshals it to my Java code. I'm attempting to achieve this using JNI and COM (without a third-party bridge). It works 75% of the time, but the other 25% of the time, the JVM crashes with the usual Hotspot crash log containing an access violation exception. However, I don't know what in my C++ code (VC++ 8) could be causing this except for passing a "wild" pointer to the code lying underneath the COM object interface. If that is the case, I don't know how I am doing that.
    The Java code that is calling my native method is running on Tomcat 5.5.25 and just to be safe, I am not allowing multiple threads to concurrently call the method in my JNI DLL (though I realize that this will kill performance). Once I can get past this problem, I'll do the COM interfacing on a worker thread in my native code so I don't screw up CoInitialize and CoUninitialize calls in the case the same thread is concurrently executing multiple calls to my native code.
    I've noticed that in most cases, the JVM crashes during my call to the pClsAccount->OpenConnection method. However, my DLL isn't what is listed on the top of the call stack, which is why I suspect the passing of a wild pointer, though I'm just taking a guess at that. Does anyone have an idea as to what's going on ?
    JNIEXPORT jobject JNICALL Java_CustomerInfo_nGetCustomerAccountInfo(JNIEnv *env, jobject customerInfo, jstring accountNumber, jstring iniFileName)
    jboolean isCopy;
    // Account info class and instance to be instantiated
    jclass accountInfoCls = NULL;
    jobject accountInfoObj = NULL;
    // The constructor ID of the accountInfoCls
    jmethodID ctorID = NULL;
    // Pointer to the interface for the ClsAccount COM object
    _clsAccount *pClsAccount = NULL;
    HRESULT hr;
    BSTR bstrIniFileName(L"");
    try
    const char *nativeAccountNumber = NULL;
    if (accountNumber != NULL)
    nativeAccountNumber = env->GetStringUTFChars(accountNumber, &isCopy);
    else
    jclass newExcCls;
    env->ExceptionDescribe();
    env->ExceptionClear();
    newExcCls = env->FindClass("java/lang/IllegalArgumentException");
    env->ThrowNew(newExcCls, "accountNumber passed in was null !");
    return NULL;
    // Initialization
    variantt varConnectionSucceeded = variantt(false);
    variantt varGetAccountInfoSucceeded = variantt(false);
    variantt varAccountNumber = variantt(nativeAccountNumber);
    bstrt bstrLastPaymentDate = bstrt();
    bstrt bstrLastErrorMessage = bstrt();
    bstrt bstrLastErrorNumber = bstrt();
    jlong jTotalDue = NULL;
    jlong jEstablishedDueDay = NULL;
    jlong jLastPaymentAmount = NULL;
    jstring jLastPaymentDate = NULL;
    jstring jLastErrorMessage = NULL;
    jstring jLastErrorNumber = NULL;
    jthrowable jException = NULL;
    const char *chLastPaymentDate = NULL;
    const char *chLastErrorMessage = NULL;
    const char *chLastErrorNumber = NULL;
    long long totalDue;
    long long lastPaymentAmount;
    long establishedDueDateDay;
    //Convert string from Java string to C string to VB string
    const char *nativeIniFileName = NULL;
    if (iniFileName != NULL)
    nativeIniFileName = env->GetStringUTFChars(iniFileName, &isCopy);
    else
    jclass newExcCls;
    env->ExceptionDescribe();
    env->ExceptionClear();
    newExcCls = env->FindClass("java/lang/IllegalArgumentException");
    env->ThrowNew(newExcCls, "iniFileName passed in was null");
    return NULL;
    bstrIniFileName = comutil::ConvertStringToBSTR(nativeIniFileName);
    CoInitialize(NULL);
    // Create an instance of the COClass with the interface over it
    hr = CoCreateInstance(__uuidof(clsAccount), NULL, CLSCTX_INPROC_SERVER, __uuidof(_clsAccount), (void **)&pClsAccount);
    if (hr == S_OK)
    varConnectionSucceeded.boolVal = pClsAccount->OpenConnection(&bstrIniFileName);
    &#12288;
    if (varConnectionSucceeded.boolVal == -1)
    varGetAccountInfoSucceeded.boolVal = pClsAccount->GetAccountPaymentInformation(&(varAccountNumber.GetVARIANT()));
    env->ReleaseStringUTFChars(accountNumber, nativeAccountNumber);
    // Extract all available account information from the ClsAccount object
    if (varGetAccountInfoSucceeded.boolVal == -1)
    totalDue = pClsAccount->TotalDue.int64;
    establishedDueDateDay = pClsAccount->EstablishedDueDateDay;
    lastPaymentAmount = pClsAccount->LastPaymentAmount.int64;
    bstrLastPaymentDate = pClsAccount->LastPaymentDate;
    chLastPaymentDate = comutil::ConvertBSTRToString(bstrLastPaymentDate.GetBSTR());
    jTotalDue = (jlong)totalDue;
    jEstablishedDueDay = (jlong)establishedDueDateDay;
    jLastPaymentAmount = (jlong)lastPaymentAmount;
    jLastPaymentDate = env->NewStringUTF(chLastPaymentDate);
    delete[] chLastPaymentDate;
    pClsAccount->CloseConnection();
    // Populate error fields if any errors occur
    bstrLastErrorMessage = pClsAccount->LastErrMessage;
    chLastErrorMessage = comutil::ConvertBSTRToString(bstrLastErrorMessage.GetBSTR());
    bstrLastErrorNumber = pClsAccount->LastErrNumber;
    chLastErrorNumber = comutil::ConvertBSTRToString(bstrLastErrorNumber.GetBSTR());
    jLastErrorMessage = env->NewStringUTF(chLastErrorMessage);
    jLastErrorNumber = env->NewStringUTF(chLastErrorNumber);
    delete[] chLastErrorMessage;
    delete[] chLastErrorNumber;
    const char* clsName = "com/nuance/merchantsmutual/businessentities/CustomerAccountInfo";
    // Find the Java class and the ID of its constructor
    accountInfoCls = env->FindClass(clsName);
    ctorID = env->GetMethodID(accountInfoCls, "<init>", "(JJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
    jException = env->ExceptionOccurred();
    if (jException != NULL)
    env->ExceptionDescribe();
    env->ExceptionClear();
    //Release all resources associated with the ClsAccount instance
    pClsAccount->Release();
    //Instantiate the class with the given parameters
    accountInfoObj = env->NewObject(accountInfoCls, ctorID, jTotalDue, jEstablishedDueDay, jLastPaymentAmount, jLastPaymentDate, jLastErrorMessage, jLastErrorNumber);
    jException = env->ExceptionOccurred();
    if (jException != NULL)
    env->ExceptionDescribe();
    env->ExceptionClear();
    else if (hr == REGDB_E_CLASSNOTREG)
    cout << "COM class not registered" << endl;
    else if ( hr == CLASS_E_NOAGGREGATION)
    cout << "COM class can't be aggregated" << endl;
    else if (hr == E_NOINTERFACE)
    cout << "No interface for COM class clsAccount" << endl;
    else if (hr == E_POINTER)
    cout << "*ppv pointer was NULL !" << endl;
    else
    cout << "Error occurred while creating COM object. HR is [" << hr << "]" << endl;
    // Free the BSTR because a new one was returned with a call to comutil::ConvertStringToBSTR
    SysFreeString(bstrIniFileName);
    // Release the string when it's no longer needed. MUST call if string won't be used
    // anymore or else a memory leak will occur
    env->ReleaseStringUTFChars(iniFileName, nativeIniFileName);
    CoUninitialize();
    &#12288;
    catch (_com_error &e)
    cout << "Encountered an exception in GetCustomerAccountInfo: Error was " << e.ErrorMessage();
    pClsAccount->Release();
    catch (...)
    pClsAccount->Release();
    return accountInfoObj;
    Edited by: Cthulhu76 on Jan 5, 2010 9:18 AM

    0x49202400 JavaThread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon [_thread_blocked, id=5340, stack(0x49bf0000,0x49c40000)]
    0x48a7e800 JavaThread "Thread-1" [_thread_in_native, id=5976, stack(0x48f00000,0x48f50000)]
    0x48a0dc00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3072, stack(0x48c60000,0x48cb0000)]
    0x48a09000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4988, stack(0x48c10000,0x48c60000)]
    0x48a07c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=3124, stack(0x48bc0000,0x48c10000)]
    0x48a07000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2572, stack(0x48b70000,0x48bc0000)]
    0x489f5c00 JavaThread "Finalizer" daemon [_thread_blocked, id=5752, stack(0x48b20000,0x48b70000)]
    0x489f4c00 JavaThread "Reference Handler" daemon [_thread_blocked, id=2596, stack(0x48ad0000,0x48b20000)]
    0x003c6000 JavaThread "main" [_thread_in_native, id=4252, stack(0x00820000,0x00870000)]
    Other Threads:
    0x489f0400 VMThread [stack: 0x48a80000,0x48ad0000] [id=5624]
    0x48a18800 WatcherThread [stack: 0x48cb0000,0x48d00000] [id=1192]
    VM state:not at safepoint (normal execution)
    VM Mutex/Monitor currently owned by a thread: None
    Heap
    def new generation total 36288K, used 12762K [0x02940000, 0x050a0000, 0x07800000)
    eden space 32256K, 34% used [0x02940000, 0x0343af58, 0x048c0000)
    from space 4032K, 37% used [0x04cb0000, 0x04e2ba28, 0x050a0000)
    to space 4032K, 0% used [0x048c0000, 0x048c0000, 0x04cb0000)
    tenured generation total 483968K, used 7518K [0x07800000, 0x250a0000, 0x42940000)
    the space 483968K, 1% used [0x07800000, 0x07f57958, 0x07f57a00, 0x250a0000)
    compacting perm gen total 14080K, used 14016K [0x42940000, 0x43700000, 0x46940000)
    the space 14080K, 99% used [0x42940000, 0x436f0320, 0x436f0400, 0x43700000)
    No shared spaces configured.
    Dynamic libraries:
    0x00400000 - 0x0040f000      C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\tomcat5.exe
    0x7c800000 - 0x7c8c0000      C:\WINDOWS\system32\ntdll.dll
    0x77e40000 - 0x77f42000      C:\WINDOWS\system32\kernel32.dll
    0x77380000 - 0x77411000      C:\WINDOWS\system32\USER32.dll
    0x77c00000 - 0x77c48000      C:\WINDOWS\system32\GDI32.dll
    0x77f50000 - 0x77feb000      C:\WINDOWS\system32\ADVAPI32.dll
    0x77c50000 - 0x77cef000      C:\WINDOWS\system32\RPCRT4.dll
    0x76f50000 - 0x76f63000      C:\WINDOWS\system32\Secur32.dll
    0x77ba0000 - 0x77bfa000      C:\WINDOWS\system32\MSVCRT.dll
    0x7c8d0000 - 0x7d0cf000      C:\WINDOWS\system32\SHELL32.dll
    0x77da0000 - 0x77df2000      C:\WINDOWS\system32\SHLWAPI.dll
    0x76290000 - 0x762ad000      C:\WINDOWS\system32\IMM32.DLL
    0x77420000 - 0x77523000      C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.3790.3959_x-ww_D8713E55\comctl32.dll
    0x6d7c0000 - 0x6da10000      C:\Program Files\Java\jre1.6.0_07\bin\client\jvm.dll
    0x76aa0000 - 0x76acd000      C:\WINDOWS\system32\WINMM.dll
    0x7c340000 - 0x7c396000      C:\WINDOWS\system32\MSVCR71.dll
    0x6d270000 - 0x6d278000      C:\Program Files\Java\jre1.6.0_07\bin\hpi.dll
    0x76b70000 - 0x76b7b000      C:\WINDOWS\system32\PSAPI.DLL
    0x6d770000 - 0x6d77c000      C:\Program Files\Java\jre1.6.0_07\bin\verify.dll
    0x6d310000 - 0x6d32f000      C:\Program Files\Java\jre1.6.0_07\bin\java.dll
    0x6d7b0000 - 0x6d7bf000      C:\Program Files\Java\jre1.6.0_07\bin\zip.dll
    0x6d570000 - 0x6d583000      C:\Program Files\Java\jre1.6.0_07\bin\net.dll
    0x71c00000 - 0x71c17000      C:\WINDOWS\system32\WS2_32.dll
    0x71bf0000 - 0x71bf8000      C:\WINDOWS\system32\WS2HELP.dll
    0x71b20000 - 0x71b61000      C:\WINDOWS\system32\mswsock.dll
    0x5f270000 - 0x5f2ca000      C:\WINDOWS\system32\hnetcfg.dll
    0x71ae0000 - 0x71ae8000      C:\WINDOWS\System32\wshtcpip.dll
    0x76ed0000 - 0x76efa000      C:\WINDOWS\system32\DNSAPI.dll
    0x76f70000 - 0x76f77000      C:\WINDOWS\System32\winrnr.dll
    0x76f10000 - 0x76f3e000      C:\WINDOWS\system32\WLDAP32.dll
    0x76f80000 - 0x76f85000      C:\WINDOWS\system32\rasadhlp.dll
    0x4a6a0000 - 0x4a6ac000      C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\CustomerInfoProxy.dll
    0x77670000 - 0x777a9000      C:\WINDOWS\system32\ole32.dll
    0x77d00000 - 0x77d8b000      C:\WINDOWS\system32\OLEAUT32.dll
    0x7c420000 - 0x7c4a7000      C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_E6967989\MSVCP80.dll
    0x78130000 - 0x781cb000      C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_E6967989\MSVCR80.dll
    0x777b0000 - 0x77833000      C:\WINDOWS\system32\CLBCatQ.DLL
    0x77010000 - 0x770d6000      C:\WINDOWS\system32\COMRes.dll
    0x77b90000 - 0x77b98000      C:\WINDOWS\system32\VERSION.dll
    0x75da0000 - 0x75e5d000      C:\WINDOWS\system32\SXS.DLL
    0x75e60000 - 0x75e87000      C:\WINDOWS\system32\apphelp.dll
    0x4dc30000 - 0x4dc5e000      C:\WINDOWS\system32\msctfime.ime
    0x4b0d0000 - 0x4b395000      C:\WINDOWS\system32\xpsp2res.dll
    0x71bb0000 - 0x71bb9000      C:\WINDOWS\system32\WSOCK32.dll
    0x4bbe0000 - 0x4bbea000      C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\ClearTranProxy.dll
    0x745e0000 - 0x7489e000      C:\WINDOWS\system32\msi.dll
    0x71c40000 - 0x71c97000      C:\WINDOWS\system32\NETAPI32.dll
    0x4bc50000 - 0x4bc6c000      C:\WINDOWS\system32\DBNETLIB.DLL
    0x71f60000 - 0x71f64000      C:\WINDOWS\system32\security.dll
    0x76c90000 - 0x76cb7000      C:\WINDOWS\system32\msv1_0.dll
    0x76cf0000 - 0x76d0a000      C:\WINDOWS\system32\iphlpapi.dll
    0x761b0000 - 0x76243000      C:\WINDOWS\system32\crypt32.dll
    0x76190000 - 0x761a2000      C:\WINDOWS\system32\MSASN1.dll
    0x4bcf0000 - 0x4bcff000      C:\Program Files\Common Files\System\Ole DB\SQLOLEDB.RLL
    0x4a8a0000 - 0x4a8aa000      C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\MIGI.DLL
    0x73570000 - 0x736c2000      C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\MSVBVM60.DLL
    0x4a950000 - 0x4a9e2000      C:\Program Files\Common Files\System\ado\msado15.dll
    0x74a50000 - 0x74a6a000      C:\WINDOWS\system32\MSDART.DLL
    0x4c850000 - 0x4c8c9000      C:\Program Files\Common Files\System\Ole DB\oledb32.dll
    0x4dbb0000 - 0x4dbc1000      C:\Program Files\Common Files\System\Ole DB\OLEDB32R.DLL
    VM Arguments:
    jvm_args: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 5.5 -Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 5.5 -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 5.5\temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\logging.properties -Djava.library.path=C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib vfprintf -Xms512m -Xmx1024m
    java_command: <unknown>
    Launcher Type: generic
    Environment Variables:
    JAVA_HOME=C:\Program Files\Java\jdk1.6.0_07
    [error occurred during error reporting (printing environment variables), id 0xc0000005]
    --------------- S Y S T E M ---------------
    OS: Windows Server 2003 family Build 3790 Service Pack 2
    CPU:total 4 (4 cores per cpu, 1 threads per core) family 6 model 7 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3
    Memory: 4k page, physical 2097151k(2097151k free), swap 4194303k(4194303k free)
    vm_info: Java HotSpot(TM) Client VM (10.0-b23) for windows-x86 JRE (1.6.0_07-b06), built on Jun 10 2008 01:14:11 by "java_re" with MS VC++ 7.1
    time: Mon Dec 28 15:24:00 2009
    elapsed time: 600 seconds

  • Java 1.5 JNI and C++ exception

    Hello, All
    I've troubles with handling C++ exceptions using JNI and shared library. I'm using Java 1.5_06, RedHat 7.3 and JBoss 4.0.5
    From Java class I call JNI a method in my shared library(libx.so) which calls a method in other shared library(liby.so). Liby.so uses Xerces library. During parsing process an exception occurs. But according to Xerces sources it's a normal behavior and should be caught. But instead I've got SIGNABRT in JVM and a core dump will created. What's wrong? Backtrace shows similar something:
    XXXXX  __default_terminate() ....
    XXXXX  __terminate() ....
    XXXXX  __throws
    XXXXX C++ method ..
    XXXXX.....
    XXXXX.....
    XXXXX  JNI methodI found similar bugs reports in the forum. But they says about Java 1.4 version and according to bugs descriptions it should be already fixed.
    Message was edited by:
    kostik78

    The question is closed. The root cause was incorrect building of shared library.

  • Trying to learn Structure and/or Array

    OK here goes my best attempt at an explanation... I been
    through some tutorial on Structures and Arrays and have an ok idea
    of what to do with them. But all the tutorials I went through had
    the variable amounts hard coded in, but I want it to come from a
    database query(s).
    I want to get a mileage total per month per riderId
    tablename: mileageLog
    table fields: ridierId, rideDate, rideDistance
    First I want to query a DB and get all the riderId numbers
    (grouped so I only have one for each). This is no problem.
    <cfquery name="riderIds" datasource="DevKevin">
    SELECT riderId
    FROM mileageLog
    GROUP BY riderId
    </cfquery>
    Now using each riderId, I want to put the results into a
    structure and/or array so that I can then turn around and sort as
    desired.
    I think I need to use a loop - one for each riderId.
    Inside each loop, I would need a second loop running 12 times
    (once for each month)
    The inner loop would run a query like...
    <cfquery name="mileageByMonth" datasource="DevKevin">
    SELECT sum(rideDistance) AS monthTotal
    FROM mileageLog
    WHERE riderId=
    ???? from above somehow
    AND year(rideDate)=#nowYear#
    AND month(rideDate)=#
    ???? loop through 12 months#
    </cfquery>
    I'm so lost

    quote:
    Originally posted by:
    2onboard
    This does indeed return the correct amounts - THANKS
    But how do I utilize them? by that I want to take my results
    and put it into a table that is 14 columns wide.
    Column 1 = the riderID
    Columns 2-13 = the monthly totals
    column 14 = a yearly total
    I also want to be able to sort by any column
    Now it becomes complicated. I'm going to assume that you want
    the current year, not the last 12 months. That means you don't
    necessarily want 14 columns. I also assume that Access's month()
    function returns a number like 4, and not a string like April. I
    don't use Access so I don't actually know.
    Step 1 - Use query of queries and valuelist to get a list of
    distinct month numbers. I'll call this variable abc.
    Step 2 - Build another list of the month names for each of
    those numbers. The function is MonthAsString. I'll call this
    variable months. Then build a third list, the same length, with the
    word integer as each element. I'll call this variable xyz.
    Step 3 - Create a new query. This will have your data in a
    cross tab format for later.
    xTab = QueryNew("Rider,#months#,total",
    "varchar,#xyz#,integer");
    Step 4 - Loop through your original query and use if/else
    logic to populate the xTab query.
    Final Step - Use a flash grid to display your xTab query.
    That will enable you to sort on any column.

  • JNI and Out of Memory errors

    Hi,
    At my job, we seem to have a memory leak related to JNI. We know we
    have a memory leak because we keep getting Out of Memory errors even
    after increasing the maximum heap size to more than 256 megs. And we
    know that this is the application that is eating up all the system
    memory.
    We are running under Windows 2000, with both JDK 1.3.0 and JDK 1.4.1.
    We tried looking at the problem under JProbe, but it shows a stable
    Java heap (no problems, except that the Windows task manager shows it
    growing and growing...)
    I tried a strip down version, where I set the max heap size to 1 Meg,
    and print out the total memory, memory used, and maximum memory used at
    a 5 sec interval.
    Memory used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory().
    Well, I let that strip down version running for about a day. The
    maximum memory used has stabilized to about 1.1 Meg, and has not
    increased. The current memory used increases until it gets to some
    threshold, then it decreases again. However, the Windows task manager
    shows the memory increasing -- and currently it is at 245 Megs!
    In the lab, the behavior we see with the Windows task manager is as
    follows:
    1. Total memory used in the system increases until some threshold.
    2. Then it goes back down by about 100 Megs.
    3. This cycle continues, but at each cycle the memory goes back down
    less and less, until the app crashes.
    Now, our theory is that JNI is consuming all this memory (maybe we are
    using JNI wrong). That's the only explanation we can come up with to
    explain what we have seen (Java showing an OK heap, but the task
    manager showing it growing, until crashing).
    Does that make sense? Can the new operator throw an Out of Memory
    error if the system does not have enough memory to give it, even if
    there is still free heap space as far as the Runtime object is
    concerned? Does the Runtime object figures objects allocated through
    JNI methods into the heap used space?
    Note that I know the task manager is not a reliable indicator.
    However, I don't think a Java app is supposed to runaway with system
    memory -- the problem is not simply that the Java app is consuming too
    much memory, but that it seems to always want more memory. Besides, we
    do get the Out of Memory error.
    Thanks for your help,
    Nicolas Rivera

    Hi,
    there are two sources of memory leakage in JNI:
    - regular leaks in c/c++ code;
    - not released local/global references of java objects in JNI.
    I think that the first issue in not a problem for you. The second is more complex. In your JNI code you should check
    - how many local references alive you keep in your code as their number is restricted (about 16 and can be enlarged). The good style is not to store local references but keep only global.
    - any local reference accepted from java call in JNI are released by JVM. You should release local references you created in JNI and also global references.
    - do not use a large number of java object references. Each new reference gets new memory in JVM. Try to reuse refences.
    I guess that is your problem.
    Vitally

  • How can i combine an array of string and an array of integers ?

    i have an array of string data [to be used as header], and an array of multiple column integer vakues;i need them together in one file. 
    Am not able to combine them so that i can write them into a single file.
    Solved!
    Go to Solution.
    Attachments:
    string file input.txt ‏1 KB
    Test build_1.vi ‏13 KB

    There are a few ways you can do this.  What I recommend is:
    Open the file
    Use the Array to Spreadsheet String to turn your headers into a single string
    Write this to the file.
    Use the Array to Spreadsheet String to turn your numeric data into a single string
    Write this to the file.
    Close the file
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How do I wrap and int array?

    Hello,
    this is my first time using the Java forum so I hope it can be helpful :)
    Im having a problem with my computer assignment at school. Here is the code im having trouble with
    private void writeObject (ObjectOutputStream out) throws IOException
         out.defaultWriteObject (); // do the default stuff
         out.writeObject (strokeColor);
         out.writeObject(xList);
         out.writeObject(yList);
         private void readObject (ObjectInputStream in) throws IOException,    ClassNotFoundException
         in.defaultReadObject (); // do the default stuff
         strokeColor = (Color) in.readObject ();
         xList = (Integer[]) in.readObject();
         yList =  (Integer[]) in.readObject();
         }In the readObject method, Im trying to restore the values of the arrays xList and yList by wrapping the data back to and integer array, but I keep getting an incompatible types error. Any suggestions?

    never mind, I just used some ArrayList objects instead and that solved the problem

  • Diffrence mailbox GUID and CAS array

    What's the diffrence between Mailbox GUID and CAS Array & What's the benefit for GUID.

    Hi,
    Mailbox GUID is the property of Exchange mailbox and we can think of the mailbox GUID as the primary key for the mailbox. It is a unique value that distinguishes an individual mailbox from all others. Regardless of which Active Directory user account owns
    the mailbox, the mailbox GUID always remains the same as long as the mailbox exists.
    CAS array is an object. It includes all CAS servers in one site and is used for high availability.
    As you know, different from previous Exchange server, all Outlook clients in Exchange 2013 uses Autodiscover to create a new connection point comprised of mailbox GUID, @ symbol, and the domain portion of the user’s primary SMTP address. This is because
    that the simple change results in a near elimination of the unwelcome message of “Your administrator has made a change to your mailbox. Please restart.”
    Thanks,
    Angela Shi
    TechNet Community Support

  • JNI and call by reference

    Hello,
    In my Java - code I have to use native C - code. The native C - function I use has got the reference parameter “read”.
    DAQmxBaseReadAnalogF64(...,&read,...);
    I do need the information the reference points on on the java layer.
    How do I pass the reference via JNI to Java – code?
    I am already returning data.
    Here is my code:
    JNIEXPORT jfloatArray JNICALL Java_JavaWrapper_readAnalog(JNIEnv *env, jobject obj, jfloat timeout, jint arraySizeInSamps)
    int32 read;
         float64 dataArray[1000]; //Größe sollte ausreichen!
         DAQmxBaseReadAnalogF64(taskHandle, arraySizeInSamps, timeout, DAQmx_Val_GroupByScanNumber,dataArray,arraySizeInSamps*2,&read,NULL);
         int i=0;
         jfloatArray ret = env->NewFloatArray(1000);
         jfloat* returnArray = env->GetFloatArrayElements(ret,NULL);
         for(i=0;i<1000;i++){
              returnArray[i] = dataArray;
         env->ReleaseFloatArrayElements(ret,returnArray,0);
         return ret;
    Edited by: 857912 on 10.05.2011 12:59

    In C you often need to pass an array and the length used separately. However in Java the arrays length is part of the array itself.
    It would appear that `read` contains the actual amount of data obtained. If this is the case, you don't need to return it, just return an array which has the right length. (This would also be more efficient)
    Perhaps the code could look like this
    int32 read;
    float64 dataArray[1000]; //Größe sollte ausreichen!
    DAQmxBaseReadAnalogF64(taskHandle, arraySizeInSamps, timeout, DAQmx_Val_GroupByScanNumber,dataArray,arraySizeInSamps*2,&read,NULL);
    jfloatArray ret = env->NewFloatArray(read);
    jfloat* returnArray = env->GetFloatArrayElements(ret,NULL);
    for(int i=0;i<read;i++){
        returnArray[i] = dataArray;
    env->ReleaseFloatArrayElements(ret,returnArray,0);
    return ret;

  • JNI and Threads Crashes

    Hi,
    I am creating a Java app using JNI to call C++ libraries a vendor has provided for us. I used a pointer upon instantiation of the C++ object, store it in the Java side, and when I need to call a method in C, would de-reference that pointer to make function call.
    This works well in a standalone Java application. However, when I use a thread to call this object, or a servlet, it will get as far as letting me make one function call in C, but other calls afterwards will cause a core dump.
    Anyone experience this before? Please share any insight you might have. Thanks in advance.
    -Justin
    Here's the code:
    =======================================
    #include <jni.h>
    #include <iostream.h>
    #include "com_jni_JNIDSM_0005fServer.h"
    #include "DSMC_Server.h"
    //Java side: public static int cObjectID
    static jobject cls = 0;
    static jfieldID fid;
    * Class: JNIDSM_0005fServer
    * Method: DSM_Server
    * Signature: ()I
    * Create an instance of this object and return a reference handler (pointer).
    * REQUIRED: Need to call this method first before DSM_Server object can be used.
    JNIEXPORT jint JNICALL Java_com_jni_JNIDSM_1Server_DSM_1Server
    (JNIEnv* p_env, jobject p_obj)
    DSMC_Server* server;
    server = new DSMC_Server();
    cout << "ServerPtr Created = " << (jint)server << endl;
    Java_com_jni_JNIDSM_1Server_setCID(p_env, p_obj, (jint) server);
    return ((jint) server);
    * Class: JNIDSM_0005fServer
    * Method: connect
    * Signature: (Ljava/lang/String;ILjava/lang/String;I)I
    * Create connection from the DSM Client to the Server. Pass in host & port of Server and
    * name assigned to the module of the DSM Client.
    JNIEXPORT jint JNICALL Java_com_jni_JNIDSM_1Server_connect
    (JNIEnv* p_env, jobject p_obj, jstring p_host, jint p_port, jstring p_serverModuleName)
    // Obtain pointer reference to corresponding DSM objects
    DSMC_Server* serverPtr = (DSMC_Server*)
    Java_com_jni_JNIDSM_1Server_getCID (p_env, p_obj);
    // Convert the Java String to a Char pointer for use
    cout << "ServerPtr in JNI_connect() begin = " << (jint) serverPtr << endl;
    jboolean isModCopy, isHostCopy;
    const char* host = p_env->GetStringUTFChars(p_host, &isHostCopy);
    const char* serverModuleName = p_env->GetStringUTFChars(p_serverModuleName, &isModCopy);
    // Call the DSM_Server object's Connect() function
    jint status = (*serverPtr).Connect (host, p_port, serverModuleName);
    // Clean up object allocation for string copy after method is done
    if (isHostCopy == JNI_TRUE)
    p_env->ReleaseStringUTFChars(p_host, host);
    if (isModCopy == JNI_TRUE)
    p_env->ReleaseStringUTFChars(p_serverModuleName, serverModuleName);
    cout << "ServerPtr in JNI_connect() after = " << (jint) serverPtr << endl;
    return status;
    * Class: JNIDSM_0005fServer
    * Method: disconnect
    * Signature: (I)V
    * Disconnect from the Server.
    JNIEXPORT void JNICALL Java_com_jni_JNIDSM_1Server_disconnect
    (JNIEnv* p_env, jobject p_obj)
    // Obtain pointer reference to corresponding DSM objects
    DSMC_Server* serverPtr = (DSMC_Server*)
    Java_com_jni_JNIDSM_1Server_getCID (p_env, p_obj);
    cout << "ServerPtr in disconnect = " << (jint) serverPtr << endl;
    // Call the DSM_Server object's Disconnect() function
    (*serverPtr).Disconnect();
    * Class: JNIDSM_0005fServer
    * Method: doHeartbeat
    * Signature: (I)I
    * Check the status of the Server. Return status code that tells the caller Server' status.
    JNIEXPORT jint JNICALL Java_com_jni_JNIDSM_1Server_doHeartbeat
    (JNIEnv* p_env, jobject p_obj, jint p_serverPtr)
    // Obtain pointer reference to corresponding DSM objects
    DSMC_Server* serverPtr = (DSMC_Server*)
    Java_com_jni_JNIDSM_1Server_getCID (p_env, p_obj);
    // Call the DSM_Server object's DoHeartbeat() function
    jint status = (*serverPtr).DoHeartbeat();
    return status;
    * Class: JNIDSM_0005fServer
    * Method: getMaxPacketSize
    * Signature: (I)I
    * Return the packet size that are being sent through this network connection.
    JNIEXPORT jint JNICALL Java_com_jni_JNIDSM_1Server_getMaxPacketSize
    (JNIEnv* p_env, jclass p_class)
    // Obtain pointer reference to corresponding DSM objects
    DSMC_Server* serverPtr = (DSMC_Server*)
    Java_com_jni_JNIDSM_1Server_getCID (p_env, p_obj);
    // Call the DSM_Server object's GetMaxPacketSize() function
    jint packetSize = (*serverPtr).GetMaxPacketSize();
    return packetSize;
    * Class: com_jni_JNIDSM_0005fServer
    * Method: getCID
    * Signature: ()J
    JNIEXPORT jlong JNICALL Java_com_jni_JNIDSM_1Server_getCID
    (JNIEnv* p_env, jobject p_obj)
         jclass clazz;
         clazz = p_env->GetObjectClass(cls);
         fid = p_env->GetStaticFieldID(clazz, "cObjectID", "J");
    jint id = p_env->GetStaticLongField(clazz, fid);
    cout << "ServerPtr retrieved w/ getCID = " << id << endl;
    return id;
    * Class: com_jni_JNIDSM_0005fServer
    * Method: setCID
    * Signature: (J)V
    JNIEXPORT void JNICALL Java_com_jni_JNIDSM_1Server_setCID
    (JNIEnv* p_env, jobject p_obj, jint p_hndlr)
         jclass clazz;
         //create global reference
         if (cls == 0) {
              clazz = p_env->GetObjectClass(p_obj);
              if (clazz == 0) {
    cout << "Error occurred while getting class ref..."<< endl;
              cls = p_env->NewGlobalRef(p_obj);
              if (cls == 0) {
    cout << "Error occurred trying to create Global ref..."<< endl;
              fid = p_env->GetStaticFieldID(clazz, "cObjectID", "J");
         } else
              clazz = p_env->GetObjectClass(cls);
    p_env->SetStaticLongField(clazz, fid, p_hndlr);
    cout << "ServerPtr saved in setCID = " << p_hndlr << endl;
    }

    Thanks Tom for your help.
    After further debugging and trying new ideas, it turns out to be something really weird within the actual C++ object. I did a very basic execution to just connect and disconnect from the server all within one function. Even with one function call, it would crash. I'm going back to the vendor to let them figure it out.
    I've done my own examples of allocating dynamic arrays, setting & getting values, then deallocating it. There were no problems with threads then.
    I know I'm not going wacky, hopefully not, but who knows. Thanks again.
    Here's the simple code that crashed within a Java thread:
    void SomeJNIFunction(<params>) {
    jboolean isModCopy, isHostCopy, isAppCopy;
    const char* host = p_env->GetStringUTFChars(p_sHost, &isHostCopy);
    const char* sModuleName = p_env->GetStringUTFChars(p_sModName, &isModCopy);
    const char* sAppName = p_env->GetStringUTFChars(p_sAppName, &isAppCopy);
    jint status = 0;
    DSMC_Server serverPtr;
    DSMC_Event eventPtr;
    cout << "In JNI, ready to connect. Host=" << host << "|ModName=" << sModuleName
    << "|AppName=" << sAppName << endl;
    // connection attempt
    status = serverPtr.Connect (host, p_iPort, sModuleName);
    cout << "(JNI) Connected ..." << endl;
    //*************crash!!!!!!!********
              serverPtr.Disconnect();
    }

  • Problem with JNI and Tomcat (and threads???)

    Howdy,
    Here is the issue - I would like some help on HOW to debug and fix this problem:
    2 test use cases -
    1)
    a)User goes to Login.jsp, enters user and password
    b) User submits to LoginServlet
    c) login calls JNI code that connects to a powerbuilder(Yes I know this is ugly) PBNI code module (this is a .dll) that authenticates the user with the database
    d) the servlet then redirects to another .jsp page
    e) user then submits to LogoutServlet - also a JNI call to a powerbuilder PBNI code module
    f) REPEAT STEPS a-e over a few times (inconsistent) and then the call to the JNI code hangs
    2)
    a) users does NOT goto Login.jsp, but rather calls LoginServlet and passes the userid and password as GET parms
    b) user does NOT get redirected to a page (redirect code commented out)
    c) user calls LogoutServlet
    d) repeat steps a-c at will and no failure, no hanging
    The only difference is that in case 1 (with JSP), there is a redirect and it afffected the JNI call by haniging inside JNI code.
    In case 2 (without JSP) there is still a JNI call, but it does not hang. In addition, when it hangs and I stop Tomcat, the logs show cleanup entries that say:
    Oct 19, 2004 9:17:09 AM org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    Oct 19, 2004 9:17:10 AM org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    Oct 19, 2004 9:17:11 AM org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    Is this a threading issue in Tomcat???
    On would assume that the JNI code is not cleaning up after itself, but I don't believe this is the case,
    and even if it was, why would I get the tomcat log cleanup entries above???
    What do those cleanup entries imply about the state of Tomcat????

    hi ,
    I met the same problem this morning, and searched the www.google.com in order to solve it, as a result, your article was shown on my screen. :)
    Till now I have read some technical information and solved my problems. Maybe the solution be useful to you:
    ==============================
    error message : (Environment : Tomcat 5, Windows 2003, Mysql5)
    2006-3-29 11:53:48 org.apache.catalina.core.StandardWrapper unload
    message: Waiting for 2 instance(s) to be deallocated
    ==============================
    cause: the number of connection to database exceeded.another word,too many connections.
    ==============================
    solution: close the connection when it becomes useless for your program. :)
    ==============================
    ps. Sorry for my weak English . hehe ....

Maybe you are looking for

  • Creative mediasource organizer not recognizing zen microph

    I jusr recently had to restore my laptop to factory settings so I had reinstall creative. But now when I open the mediasource to try to get songs off of my microphoto on onto my laptop, it doesn't show my zen in the little dropdown where it shoes pc

  • PO mod right after a purchase order is authorized...where?

    I have a customer that is implementing procurement, but not financials. Thus, in PO, it can't do funds checking and such. I need to write an exit mod which will send information to a 3rd party application via a web service right after a requisition/p

  • MB_MIGO_BADI. Post document. Posting date?

    Hi Guys, I need your help. I'm using MB_MIGO_BADI, method post_document to change posting date in header. After user changed the posting date I need to check some conditions and if they are fulfilled I want to change this posting date with sending th

  • My time machine just stopped working. No power. I had it since 2011

    I had my time machine for about 20 months, and it just stopped working. no power. I have a lot of backups on it. Anyone had the same issue? I read on some forums that it was reccurent, and that apple is not addressing this issue. Please help. Too exp

  • Webcams Not Working With Flash

    I'm using Windows 8 64 bit, have tried on both chrome and firefox, flash version 11.8. I'm trying to broadcast my webcam and audio in flash chat rooms. When I'm prompted to choose my video and audio sources the options show up but they can not be uti