Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Retrieving arrays of java class inside C++ code

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Retrieving arrays of java class inside C++ code

    Hi everyone,

    Currently i am working on JNI for native access between java and c++.

    Here goes my doubt:

    If i have to access an integer field (present inside my java class) in my c++ code, then the code is like this:
    jclass testC = env->FindClass("class name");
    jfieldID fid1 = env->GetFieldID(testC,"var","I");  //assuming the field name is var(type-int)
    jobject objC = env->AllocObject(testC);
    jint ret = env->GetIntField(objC,fid1);      //retrieving the value
    ret = 89;
    env->SetIntField(objC,fid1,ret);    //changing the value of 'var'

    But my problem is, if in the above case i have an integer array (instead of just an int),
    and i want to perform similar get and set operations on the array, then what would be the code?

    I have tried a lot for this, but not able to achieve this.

    It would be really great, if someone can fix this problem.

    With regards,
    sattu


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Retrieving arrays of java class inside C++ code

    Take a look at Accessing Basic Types, Strings, and Arrays using JNI. Section 3.3 details how to access both primitive and object arrays in C/C++ code.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    sattu (May 20th, 2011)

  4. #3
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Retrieving arrays of java class inside C++ code

    Thanks helloworld,
    The link you provided is really beneficial. Will go through it.

    With regards,
    Satya Prakash.

Similar Threads

  1. Replies: 1
    Last Post: December 22nd, 2011, 08:55 AM
  2. How to Sort an Array using the java.util.Arrays class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 22nd, 2011, 08:53 AM
  3. Issue with setting up different class with arrays
    By D-COD3R in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2011, 06:09 PM
  4. Help with java retrieving from Ms Access
    By dever in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 10:40 AM
  5. [SOLVED] Passing arrayList inside class
    By KrisTheSavage in forum Collections and Generics
    Replies: 1
    Last Post: March 27th, 2010, 12:45 PM