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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:23:52+00:00 2026-06-18T00:23:52+00:00

I get this problem when I wanna call a native C function in java

  • 0

I get this problem when I wanna call a native C function in java on android use JNI. I pass a pointer to structure as a parameter in that C function, and allocate memory to that pointer.

So please tell me how can I call this C function in java? I googled for a long time but get no rewards.

Codes like this, A is the name of structure :

JNIEXPORT int JNICALL
Java_pkgname_NativeTools_create(JNIEnv *env, jclass jclazz, A **ptr) {
    *ptr = (A*) malloc(sizeof(A));
    if (*ptr != NULL ) {
        return 0;
    } else {
        return -1;
    }
}

and I don’t know how to write the native interface :

public class NativeTools{
    static {
        System.loadLibrary("LibName");
    }

    // TODO don't know what type in JNI should I use to declare this native function?
    public static native int create(?);
}

thanks a lot and sorry for my poor english 🙁

  • 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-18T00:23:54+00:00Added an answer on June 18, 2026 at 12:23 am

    You can’t do it like this. You can use only JNI datatypes as C function parameters. Anyway, there is nothing like structs or even pointers in Java. What was it, that you wanted to create on Java side and then “pass it to C” ? The nearest to pointer you could get is a reference type jobject, but C doesn’t understand it as simply as you tried. It’s a reference to JVM object, not C struct. It’s only meant as a parameter to further JNI calls (which calls back to JVM).

    There are tools which could help you improving the datatype interoperability (SWIG,JNA), but given the apparent fundamental misunderstanding, you should start with some basic reading:

    http://192.9.162.55/docs/books/jni/html/jniTOC.html
    

    (can’t do a proper link, SO forbids IP addresses)

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

Sidebar

Related Questions

I get this problem while doing some experiment with set . I use a
So I am running into this problem. I am trying to use $.get() to
I get this problem when referring to OpenFEC (openfec.org)-functions in my code: anders@ubuntu:~/workspace/fectest$ gcc
I periodically get this problem where all of a sudden mako is using old
Hope to get solution to this problem. I have been stuck on it since
Hi i got stuck with this problem, i can't find out how to get
I have been tackling this problem for some time. I get the image from
I have a problem with this query trying to get a sum and a
This is my problem. Every time I load the page, I get an alert
I am having problem to get a numerical value for this expression where 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.