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 6016065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:55:46+00:00 2026-05-23T02:55:46+00:00

In JNI when we want to pass a string from C to java we

  • 0

In JNI when we want to pass a string from C to java we do it by(C++):

return env->NewStringUTF("MY String");

As this is a return statement, it can be called just once ie. Only 1 string can be passed from C to Java.

What about the function in which we want to pass multiple String from C to Java?!

For example consider the case in which a function wants to pass multiple strings:

void num()
{
    for(int i=0;i<10;i++)
    {
        pass i from C to java..
    }
}

How can I do such thing?

Note: I know this can be achieved by using string array or by concatenating i and return the string at last .Also, I know i is a integer, and I know how to convert integer to String in c++.

Consider this is a necessity to pass i as the loop runs though that i(which is passed).

It’ll be good if the function remains to be void.

  • 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-23T02:55:47+00:00Added an answer on May 23, 2026 at 2:55 am

    This can be achieved by
    a) calling java methods (call backs) in the for loop (which are essentially setters for the required array).
    b) passing jbyte(int) array as argument and filling it in loop.
    c) method you mentioned in question – packing the return object(in byte array) and returning it ; unpack it in java side.

    option which you are not interested is the best approach and the general approach adopted.
    The main emphasis in JNI code is to reduce calls across Java-C (vice versa). Try to revise your options if your are writing non trivial code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return array of string from JNI to java(actully in android). How
I want to use the NSStatusBar object from my Java application using JNI. I
I'd like to pass java class object to JNI method, And I want to
I'm trying to pass a structure as a pointer from JNI to Java to
I'm writing some JNI code in C++ to be called from an applet on
I'm just about to make my first trip into the world of JNI (Java
I want to use DTLS (on OpenSSL) using JNI on Android 2.1/2.2. Can someone
I have an Android Application which uses JNI calls. Now i want this application
I want to include a C library in my Java project via JNI. I
I want to include a C library in my Java project via JNI. I

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.