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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:46:26+00:00 2026-05-25T16:46:26+00:00

I’d need to transfer data between my Java objects and an external OCaml program

  • 0

I’d need to transfer data between my Java objects and an external OCaml program via JNI interface but I have troubles to access object fields in the native code.

On the Java side, I have a class with several fields:

public class GPSState {

        int fix;
        double course;
        double hmsl;
        ...
}

I’m passing an object jstate of the GPSState class to the C part, where I’m trying to set its fields to respective values provided by the external program which are saved in local struct state:

jclass cls;
jfieldID fid;

cls = (*env)->GetObjectClass( env, jstate);

fid = (*env)->GetFieldID( env, cls, "fix", "I");
(*env)->SetIntField( env, cls, fid, state.fix);

fid = (*env)->GetFieldID( env, cls, "course", "D");
(*env)->SetDoubleField( env, cls, fid, state.course); 

fid = (*env)->GetFieldID( env, cls, "hmsl", "D");
(*env)->SetDoubleField( env, cls, fid, state.hmsl);

...

From debug prints I’ve learned that class is successfuly located and the fix and course fields are properly identified and set. But after the execution of SetDoubleField call on course field, which is confirmed by a debug print immediately following the call line, I always get SIGSEGV fatal error when I try to access any other field:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x01109720, pid=11665, tid=3079347056
#

Later I’ve found out, that when I move the code manipulating the course field to the very end of the C function which sets the fields, the error disappears and all fields are set as expected without any problems.

I’ve tried to run the code on another machine with another JRE implementation but the result was the same, except the error then occured after setting the first fix field (moving the respective bit of the code to the end of the function “solved” the problem again).

Now, I know I’m somehow messing up the memory but I can’t figure out where and how. I’ve followed the Fields and Method chapter in JNI Programmer’s Guide to check for possible mistakes but it seems to me that I do everything by the book. Would somebody more experienced be so kind and point out where the problem could be?

  • 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-25T16:46:27+00:00Added an answer on May 25, 2026 at 4:46 pm
    (*env)->SetIntField( env, cls, fid, state.fix);
    

    This doesn’t look right. You are trying to set an object instance field, but you are passing cls instead of jstate as the object to access. You should use the following instead:

    (*env)->SetIntField( env, jstate, fid, state.fix);
    

    Make the corresponding change for your other Set<type>Field calls as well.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.