Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 413941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:14:01+00:00 2026-05-12T18:14:01+00:00

I am attempting to use the android NDK. Is there a way to return

  • 0

I am attempting to use the android NDK.

Is there a way to return an array (in my case an int[]) created in JNI to Java? If so, please provide a quick example of the JNI function that would do this.

-Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:14:02+00:00Added an answer on May 12, 2026 at 6:14 pm

    If you’ve examined the documentation and still have questions that should be part of your initial question. In this case, the JNI function in the example creates a number of arrays. The outer array is comprised of an ‘Object’ array creating with the JNI function NewObjectArray(). From the perspective of JNI, that’s all a two dimensional array is, an object array containing a number of other inner arrays.

    The following for loop creates the inner arrays which are of type int[] using the JNI function NewIntArray(). If you just wanted to return a single dimensional array of ints, then the NewIntArray() function is what you’d use to create the return value. If you wanted to create a single dimensional array of Strings then you’d use the NewObjectArray() function but with a different parameter for the class.

    Since you want to return an int array, then your code is going to look something like this:

    JNIEXPORT jintArray JNICALL Java_ArrayTest_initIntArray(JNIEnv *env, jclass cls, int size)
    {
     jintArray result;
     result = (*env)->NewIntArray(env, size);
     if (result == NULL) {
         return NULL; /* out of memory error thrown */
     }
     int i;
     // fill a temp structure to use to populate the java int array
     jint fill[size];
     for (i = 0; i < size; i++) {
         fill[i] = 0; // put whatever logic you want to populate the values here.
     }
     // move from the temp structure to the java structure
     (*env)->SetIntArrayRegion(env, result, 0, size, fill);
     return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to use a few of the simple android examples for Tab
I am attempting to use a custom font for a TextView on Android, following
I'm attempting to use OpenCV (on Android) in a project, however I'm struggling to
I have been attempting to use an android.preference.DialogPreference inflated from XML, but the documentation
In attempting to use scipy's quad method to integrate a gaussian (lets say there's
I'm (attempting) to use push notifications with Android via Urban Airship. I've register for
I am attempting to use the layout tricks #3 described in Android Layout Tricks
My goal is to compile the kiss_fft libraries to use in JNI for android
I've been toying around in Android and attempting to port over a Java app.
I'm attempting to use both progressive and cached sound files in my android app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.