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

  • Home
  • SEARCH
  • 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 8721511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:14:02+00:00 2026-06-13T07:14:02+00:00

I have need to pass List of Strings from Java to C through JNI.

  • 0

I have need to pass List of Strings from Java to C through JNI.
My Java program pass a List argument and C program accepts a list.

Below is the code which I tried.

JNIEXPORT jobject JNICALL Java_jni_CallJNIfunction(JNIEnv *env,  
                                                         jobjectArray jParameters){

    list<const char*> cParameters;

    jsize stringCount = env->GetArrayLength(jParameters);

    for (int i=0; i<stringCount; i++) {
       jstring arrElement = (jstring) (env->GetObjectArrayElement(jParameters, i));
       const char* nativeElement = env->GetStringUTFChars( arrElement, NULL);

       cParameters.push_back(nativeElement);
       env->ReleaseStringUTFChars(arrElement, nativeElement);
    }

    CallCfunction(cParameters);

}

But my JVM crashes at GetStringUTFChars() line.
What is the wrong with this program?

  • 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-06-13T07:14:03+00:00Added an answer on June 13, 2026 at 7:14 am

    You do:

    const char* nativeElement = env->GetStringUTFChars( arrElement, NULL);
    cParameters.push_back( nativeElement );
    env->ReleaseStringUTFChars(arrElement, nativeElement);
    

    You release the strings you store into a list, so your list contains a lot of bad pointers!

    You must copy the string into a long time allocated space, you have the choice between std::string, char*+malloc, or use-it-and-forget-it approach.

    Explanation for the third solution :

    for( int i = 0; i < stringCount; ++i )
    {
       jstring arrElement = (jstring) (env->GetObjectArrayElement(jParameters, i));
       const char* nativeElement = env->GetStringUTFChars( arrElement, NULL);
       CallCfunction( nativeElement ); // modified to process an item not a list<
       env->ReleaseStringUTFChars(arrElement, nativeElement);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of strings that I need to pass to a process
I have a list of integers or of strings and need to pass it
I have an application in which I need to pass an array from C#
I have a method that uses a list which I need to pass into
I have a server script that I need to pass data to from the
So I have a flashobject which I need to pass a formatted DateTime string
I have to invoke a restful Web-Service from client side java class. I need
I need to pass an array of objects, which contain arrays, from javascript to
I need to pass a List<string> or List<object> to consume WCF soap service from
I have some function where I need to pass a point datatype . somefunc(United

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.