How to return a array which be created in native method?

i wrote my native method like this:
jintarray array=env->Newintarray(10);
jint* p=env->GetIntArrayElements(array,0);
for(int i=0;i<10;i++){
p=i;
return array;
the result is that i got a array which has ten elements and all the elements are 0.
it seems the value of the array never be chenged.
how can i do? where is the mistake? how can i get the correct result?

Not quite clear what you are trying to do.
o You create a java in array, which will be initialized to zeroes.
o You then asked to access that array (as p), but you didn't pass a pointer to a boolean so it can tell you whether p points into the java array, or is a separate memory area.
o You assigned a bunch of int values to p - not p[0], p [1], ....?
o You returned to java the original array.
Here's some (untested) code that will likely work:
jBoolean isCopy;
jintarray array=env->Newintarray(10);
jint* p=env->GetIntArrayElements(array,&isCopy);
for(int i=0;i<10;i++){
p=i;
if (isCopy == JNI_TRUE)
env->ReleaseIntArrayElements(array, p, 0);
return array;

Similar Messages

  • C++ do not support  JNi && how to return the array from jni?

    hi,
    1.. I have created the Cpp file to implemement the native method but it seems that the native method can not complie rightly , it tells me follows
    error C2819: type 'JNIEnv_' does not have an overloaded member 'operator ->'
    c:\program files\microsoft visual studio\vc98\include\jni.h(764) : see declaration of 'JNIEnv_'
    c:\users\wangyue\desktop\java_gui\beattrack 5.6 - ������_������_������������ 5.7\beattrack.cpp(202) : error C2227: left of '->GetByteArrayRegion' must point to class/struct/union
    then I use the c file to paste the same code, it can complie rightly , why? I really need my native method to complie rightly in Cpp file, how to solve it?
    2.I want to return a double, for the most simple way, I do the following
    #include "RealBeatTrack_BeatTrack.h"
    JNIEXPORT jdoubleArray JNICALL Java_playaudio_BeatTrack_BeatTrack
    (JNIEnv *env, jobject j, jbyteArray data)
    jdouble outdata[4]={1,2,3,4};
    return (*env)->NewDoubleArray(env, outdata);
    then in the java code, I difine a array to receive it,
    say double mydata[] = new double[4];
    mydata= BeatTrack(buffedata);
    but the java comlier tells me the Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space?
    anyone can help me?
    Thanks

    thanks for your reply
    another problem of my!
    the jni pass the string, I then convert it to the
    const char* filename = env->GetStringUTFChars(fname,NULL);
    then I use the filename to opent the file but fails, what is the problem???
    FILE *fp= fopen(filename,"w"); // there are some problem here!!!
         fprintf(fp, "%s\n","wangyue fighting!");
    the error is as follows
    # An unexpected error has been detected by Java Runtime Environment:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0bfc1a55, pid=7040, tid=11384
    # Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode windows-x86)
    # Problematic frame:
    # C [beattrack.dll+0x1a55]
    # An error report file with more information is saved as:
    # D:\programs\playAudio\hs_err_pid7040.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #

  • How to pass an array which in the jsp to a javascript file

    now i have 2 files: jsp and js(javascript)
    i want pass an array which in the jsp to another file--> js file
    how can i do it ???
    can u give me some related links or some source codes as the references???
    thx

    bcos ....my senior has resigned!!! so i take over his job !!!!!
    depend on the talent and the project ....only that way to implement to whole project !!!!
    but , i had settled it already ....
    it is very simple
    in the middle.jsp
    Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnuserId());
    String menuname[]=new String[110];
    int menucounter=0;
    Iterator vi = result.iterator();
    while(vi.hasNext())
    HashMap hm=(HashMap)vi.next();
    menuname[menucounter]=hm.toString();
    menucounter++;
    int i;
    String tempstr="";
    for(i=0;i<menuname.length;i++)
    tempstr+=menuname[i]+",";
    session.setAttribute("menuname",tempstr);
    %>
    <script language="javascript">
    menu123("<%=tempstr %>");
    </script>
    in the body,js
    function menu123(string123)
    //doing
    so ....through the script --menu123
    i can get the string from jsp to the js!!!!!
    is it very simple, but it spends my 2 days!!!
    i just learn javascript ....about 1 month !!!

  • How can i pass array as argument in magento api method calling using sudzc API in iphone Native APP

    0down votefavorite
    I am implementing magento standard api method in native iphone app. I use webservice generated by sudzc. To call method I use:
    [service call:self action:@selector(callHandler:) sessionId:@" " resourcePath:@" " args:@""];
    When I used methods e.g. cart.info or product.info in which I have to pass one parameter; it gives valid response. But when I used method e.g. cart_product.add in which I have to pass an argument as value of array it gives error
    SQLSTATE[42000]: Syntax error or access violation:
        1064 You have an error in your SQL syntax;
        check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
    I have tested in SOAP UI also. There also it gives me same error. But same method works in PHP file. Even I tried by creating same soap request which I created using JavaScript but still it doesn't work.
    Can anyone help me to pass array as a parameter using sudzc api to call magento web services?

    There is an error in your SQL.

  • How to register transport requests which is created outside CHaRM

    Hi Experts
    I have completed the ChaRM configuration in Solution Manager.
    Now I want to include the open transport requests (which I have created outside of ChaRM) in ChaRM. Could you please guide me how I can include these open transports in ChaRM.
    Thanks in advance
    Regards
    Venkat

    Hi Prakhar
    Thanks for your reply,  as per SAP Note 1150426 I have executed the task  in the maintenance cycle "Register transport request in tasklist", but the transport request is not added to the Change request.
    Then I have tried to execute through sa38 there it's saying "Unable to find the task list / status of task list is not active". we are in ST - SAPKITL434
    Could you please check and help me to resolve the issue
    Thanks & Regards
    Venkat

  • How to return rows from tmp table created inside function??

    Hi,
    I'm trying to return rows from a cursor or table (created within
    the function). How do I specify the return type?

    Hi,
    Here is the code that examples to create a function that can
    return data from table.This is achieved using REFCURSOR concept.
    Hope this helps you.I'm giving all stuff in single PL/SQL
    block.You can break it and create a package and declare
    refcursor type and function in that as well.
    DECLARE
    -- Declare generic cursor type
    TYPE gencur_type IS REF CURSOR ;
    -- Declare generic cursor varaible
    gencur gencur_type;
    -- Declare record type
    TYPE rec_type IS RECORD(descr emp.ename%type) ;
    -- Declare record type variable
    rec rec_type;
    --This how you declare a local function that returns gencrtype
    data set
    --This function is called in main block
    FUNCTION call_refcur return gencur_type
    AS
              rr gencur_type;
    BEGIN
         OPEN rr FOR SELECT descr FROM emp;
         RETURN rr;
    END;-- end of local function
    -- Main block begins here
    BEGIN
    -- Call the local function so that gencur will have
    -- the data set returned by select statement
    gencur:= call_refcur;
    -- Open a loop to test the stuff
    LOOP
         FETCH gencur INTO rec;
         EXIT WHEN gencur%NOTFOUND;
         null;
         dbms_output.put_line(rec.ename);
    END LOOP;
    END;
    Regards,
    Sridhar

  • How to pick the file which is created with current date

    Hello All,
    I have an FTP server where files are created with current date as PO_CONFIRM_20100701.txt.
    Need to pick the file based on current date. How to pick the above file format using file sender adapter. i.e what file pattern can we use so that file will be picked only on today's date
    Regards,
    Sreenivas.

    Hi Srinivas,
    It depends upon the OS you are using. If unix you can see an example script here:
    http://www.computing.net/answers/dos/batch-file-to-rename-files-by-date/5517.html
    If windows an example here:
    http://en.kioskea.net/forum/affich-87157-finding-and-using-file-date-in-batch-command
    You may need to change slightly to fit your exact requirements. But this would make you to start. Else you can also google to get the script. Here is one link:
    http://www.google.com/#hl=en&source=hp&q=scripttorenamefileshavingtodaysdate&aq=f&aqi=m1&aql=&oq=&gs_rfai=CRE9SwTMsTNjiDpzGhgTm65iFCwAAAKoEBU_QC2i-&fp=e0fa4b5da4f245a4
    Regards,
    ---Satish

  • Now using imovie 11, how to import imovie projects which were created in an earlier version of iMovie?

    anyone got a similar situation?

    Excellent information from John, to which it may be worth adding that you can of course continue to run iMovie 6 alongside iMovie 11 on your Mac:
    Happily this is easily achieved, but it has to be done backwards.
    Delete iMovie 11 (just drag it to the trash). Now install iMovie 6 from the iLife 6 install disks. Update it to iMovie 6.0.3.
    Now re-install iMovie 11. This automatically moves iMovie 6 into a folder it creates in your Applications folder called iMovie Previous Version.
    Then reinstall iMovie 11.
    iMovie 6 works great with iDVD 7.
    Now you have them both, and you can have both in the Dock as well.

  • How to use a map which is created in mapbuilder

    Hi ,
    I have created a map by using map builder and now i want to open in IE browser through map viewer, can any one guide me through this process please
    I have created few themes and base map in map builder , i can see my map in mapbuilder but how to open in IE
    Edited by: user12078402 on 24-Feb-2010 12:36

    To display map in browser you should use JavaAPI or JavascriptAPI from mapviewer

  • How to return and display an image created by a Struts 2 action object?

    Hi all, I'm Andrea and this is my first post on SDN.
    I'm developing a web based application using Struts 2 and I've got a problem with images management. It follows a brief description:
    Using a form in a jsp page it is possible to make a call to the execute() method implemented in a class, extending ActionSupport.
    At the end of the method there's the following instruction:
    BufferedImage image = generateChart();
    My problem is that I need to return this image to the client, so that his browser could display it.
    Unfortunately I don't know exactly how to proceed.
    I've seen it's possible to define result type for Struts 2 actions through xml config file, but I don't what I need to write into che action class.
    Could you help me with this topic?

    Ok I found the answer to your problem. If you download the tutorial they have the code there it's in one folder. I hope this helps.
    http://java.sun.com/docs/books/tutorial/

  • How to copy the bookmarks which are created in SAP BW 7.3 to New SAP BW on Hana System?

    Hi,
    We have requirement of moving the Bookmarks from SAP BW 7.3 system to New  SAP BW on Hana System.
    Please let me know if it is possible?  If possible  how to do it.?
    Thanks,
    tms

    Hi TMS,
          Are you talking about Web template bookmark or QueryDesigner bookmark?
    If yes then in both the cases its is stored in your client machine as a browser favourite.This has nothing to do with HANA or BW system.So you can transfer browser favourite file from one system to other.
    If you are talking about in anyother context please be precise and more elaborate .
    Thanks & Regards
      A.Dinesh

  • How to use 'build array' (concatenate) to create a array horizontally?????HELP

    I want to link nine arrays whose dimension is 2*2 horizontally,but the function 'build array' (concatenated way) made them vertically.........help me please..........maybe this is too simple.........since I am only a students who learnd labview only few months..
    Solved!
    Go to Solution.

    A transpose operation only solves certain scenarios, but you don't give enough information on what you actually want.
    For example, of you have 3 2x2 arrays:
    a1 a2     b1 b2     c1 c2
    a3 a4     b3 b4     c3 c4
    What should the final vertical result be?
    a1 a2
    a3 a4
    b1 b2
    b3 b4
    c1 c2
    c3 c4
    or
    a1 a3
    a2 a4
    b1 b3
    b2 b4
    c1 c3
    c2 c4
    Or something else?
    Please be much more specific. Maybe even attach a small VI containing typical default data.
    LabVIEW Champion . Do more with less code and in less time .

  • How can be delete file which is created with spool command on Oracle Server

    Dear Experts,
    we have ccreated a file in oracle with DBMS_SQL Package now i want to remove this file from Server with oracle commend or Scheduler .
    Please help us.

    user8725480 wrote:
    Host Script i am not aware about that. Could you please tell me about the same.Using the DBMS_SCHEDULER package you can launch an external executable. Using this you can launch a host script in a language of your choice (BASH, VBS, etc) to perform the actions you require.

  • Returning int array from C to Java as method parameter

    Hello,
    I've been trying to accomplish this
    Java
    int[] myArray = ... (filled with some data);
    int retCode = myNativeCall(myArray);
    if(retCode == 0)
    doSomethingWith(myArray); //myArray gets overwritten with new data (with new size also) during the native call...
    C
    JNIEXPORT jint JNICALL Java_GenChav_rsaEncrypt(JNIEnv *env, jobject obj, jintArray myArray){
    jintArray outbuf;
    int[] new_array = .. // some function will fill this....
    int new_array_length = ...//some function will give me the new size, not big, 512 max...
    jint tmp[new_array_length]; //allocate..need something more ??
    memcpy(tmp, new_array, new_array_lenght);
    outbuf=(*env)->NewIntArray(env, new_array_length);
    (*env)->SetIntArrayRegion(env, outbuf, 0, new_array_length, tmp);
    myArray=outbuf;
    I tought this way I would have a updated myArray ints on the Java program...
    Any thought??

    user5945780 wrote:
    Ok, let's try to be constructive here...
    How I do implement a return type for my method like a int array ?First realized it has nothing to do with JNI. So the same question and answer applies to java only.
    >
    like:
    int[] return = myNativeCall();
    Yes.
    Then I will look for return[0], if it is == to 0, fine, it means a successful calculation by the native code. Not sure what that means. The structure of what you return it up to you.
    It can help when you are unsure of what to do in JNI....write a pseudo representation of what you want to do in a java method. Then translate that java method into JNI, everything in the pseudo method must be in the JNI code.

  • How to use a C function as a native method

    Could anybody tell me how to use a C function as a Java native method.
    Thanks

    Read all about it.
    You'd probably have to write a little wrapper (using JNI) that passes
    parameters and return values around between your C function and
    the JVM.
    kind regards,
    Jos

Maybe you are looking for

  • Help with Motion Tracking and Masking?

    Hi. First and probably only post here. I've got a bit of an issue.... I'm trying to create "snapshots" in my video that are created from masks which are then motion tracked and remain stationary. Here's a video of what i'm talking about... http://www

  • How to enable change password feature in SAP Netweaver Portal 7?

    Hi experts, I would like to provide a change password link just beside the logout link after user had successfully logged in to Sap Netweaver portal. When user clicks that link, a change password screen sill appear to allow user to change his/her pas

  • POSITION function

    Hello Experts, I am using the following column formula: POSITION('Administrators' in valueof (NQ_SESSION.GROUP)). This returns value 65 if the logged in user is a part of the Administrator Group else it returns 0. The problem is I want to convert thi

  • Installing ODAC.Exe Problem - Please Help!

    Greetings! This is the scenario: 1- I have downloaded ODAC Software Release 10.1.0.4.0 to a folder in my Windows 2003 server. (This Worked and the size downloaded is the same as the one shown in the Oracle Website) 2- I double-clicked the .exe file t

  • Update from 3.5 FMS to 5 pro

    Hi,      we have a couple of streaming interactive servers that are 3.5 and 4, do we need to purchase the full 5 pro licence or just an upgarde one?     Also are there any issues with running the update process, or should we do a clean install?    Fi