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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:46:01+00:00 2026-06-14T10:46:01+00:00

I need help with my android project. I want to pass a buffer from

  • 0

I need help with my android project.
I want to pass a buffer from java to jni, and my C++ code will populate the data. Then java will display them on the screen.
I am not familiar much with C++ and have no idea how to write to write to the buffer.

this is what i got.
in java

ByteBuffer bb = ByteBuffer.allocateDirect(216);
        IssmJni.processBuffer(bb);

native method

public static native void processBuffer(ByteBuffer bb);

I don’t use jni_onload, so no javah
in C++

static void fillBuffer(JNIEnv *env, jclass clazz, jobject buf)
    {
        double *dBuf = env->GetDirectBufferAddress(env, buf);

    }

I am stuck here, can I do double dbuf? or is it has to be a char?

Let said I want to write 1,2,3,4,5 to this dbuf, how do I do it?
i am thinking of dbuf.put(1); … dbuf.put(5) but it is not working.
and after populating it, do I just call bb.get(position) in java?

Someone clarify this for me please, example would be appreciated
Thank you

this is my table of native methods

static JNINativeMethod method_table[] = {

{"fac"      ,     "(J)J" , (void *) factorial},
    {"getBuffer",     "()[D" , (void *) getBufferNative},
    //{"processBuffer", "(Ljava/nio/ByteBuffer)V", (void *) fillBuffer}};

The other two works fine except the last one.

  • 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-14T10:46:04+00:00Added an answer on June 14, 2026 at 10:46 am

    I don’t use jni_onload, so no javah in C++

    It may be irrelevant to your question, but you sort of have to do one or the other. You either need to do your Java-to-Native method mapping in the onLoad function or use javah to generate the method signatures that JNI can pick up at runtime. Otherwise your native methods will never be invoked.

    If your native method is properly being called, however, whatever you are doing is probably fine.

    I am stuck here, can I do double dbuf? or is it has to be a char?

    The return value of the function is actually a void*, so you can cast it to whatever pointer type you want since it is just a memory address. However, the actual data type of the direct buffer will be jbyte, which is a typedef of signed char, so the following is probably best:

    jbyte *dBuf = env->GetDirectBufferAddress(env, buf);
    

    Let said I want to write 1,2,3,4,5 to this dbuf, how do I do it?

    The notation in C/C++ to access values in an array is with [] notations, i.e.:

    jbyte *dBuf = env->GetDirectBufferAddress(env, buf);
    
    dBuf[0] = 63;
    dBuf[1] = 127;
    // ...and so on...
    

    and after populating it, do I just call bb.get(position) in java?

    Yes, you can use the accessor methods on ByteBuffer to access the data you have written from your native code.

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

Sidebar

Related Questions

I don't want code, just need help finding where to start this project. I
I need help... I got errors with my android xml... Here's the code: <?xml
Need help, I am tring to make an android game as project for my
I need some help with properly versioning my Android project with Git/Eclipse. I have
i need some help on my android project. i have a canvas and i
I need help with Android. I'm trying to create a slot machine game. So,
I need help on encryption/decryption on Android application. I explain the situation. I'm actually
I am new to android and need help on this. I have two views
I need help to find the correct command, on android, to remove the blue
Hello i am new in android and i really need help with something. 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.