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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:27:40+00:00 2026-05-22T03:27:40+00:00

In fact I have this working, just not correctly. I have a callback (posted

  • 0

In fact I have this working, just not correctly. I have a callback (posted in a previous question: Unable to get JNIEnv* value in arbitrary context), which now calls a callback in the Java layer… The only problem is the datatype that the callback returns. In my Java code, when debugging, I see that the type of what the callback passes to Java is of the type class [B instead of the type byte[] what I expect.

The only thing that the Java callback does is place it in a Queue, but the problem arises when I need to process that Queue.

The callback in Java:

public void enqueueAudio(byte[] audioData){
    if(audioData != null){
        mWriteQueue.offer(audioData);
    }
}

Processing of the Queue:

private void writeToFile(String file){
    int totalNumOfBytes = 0;
    byte[] dataFromQueue = new byte[0];
    byte[] temp;
    for(byte[] data : mWriteQueue){
        temp = dataFromQueue;
        dataFromQueue = new byte[temp.length + data.length];
        System.arraycopy(temp, 0, dataFromQueue, 0, temp.length);
        System.arraycopy(data, 0, dataFromQueue, temp.length, data.length);
        totalNumOfBytes += data.length;
    }
    // Write the total byte[] to the specified file.
    mFileHandler.write(file, dataFromQueue);
    updateUI("Number of bytes written to " + file + " : " + totalNumOfBytes + "\n");
}

As you can see, I assume that the Queue is filled with byte[]‘s, and not with class [B‘s, resulting in class cast exceptions…

So, is it correct that the native code returns a class [B instead of a byte[]?

For the sake of completeness, here is the method in C:

void recorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context){
    SLresult result;
    JNIEnv* env;
    jbyteArray data;
    (*javaVM)->AttachCurrentThread(javaVM, &env, NULL);
    if(env == NULL){
        LOG_ERROR("Could not get JNIEnv*");
        return;
    }
    data = (*env)->NewByteArray(env, MAX_PACKET_SIZE);
    if(data == NULL){
        LOG_ERROR("No memory could be allocated for buffer");
        return;
    }
    (*env)->SetByteArrayRegion(env, data, 0, MAX_PACKET_SIZE, recorderBuffer);
    (*env)->CallByteMethodA(env, javaObject, javaCallbackMID, data);
    (*env)->DeleteLocalRef(env, data);
    result = (*bq)->Enqueue(bq, recorderBuffer,
                            RECORDER_FRAMES * sizeof(jbyte));
    checkError(result, "Unable to enqueue new buffer");
    (*javaVM)->DetachCurrentThread(javaVM);
}
  • 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-22T03:27:41+00:00Added an answer on May 22, 2026 at 3:27 am

    In fact I have this working, just not
    correctly.

    That’s a contradiction in terms.

      (*env)->CallByteMethodA(env, javaObject, javaCallbackMID, data);
    

    It’s not a ByteMethod. It’s a VoidMethod.

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

Sidebar

Related Questions

I have to preface this with the fact that I love jQuery as a
I have a table with arbitrary columns and rows. This fact is irrelevant though
I'm not seeing any real advantages, other than the fact that you have a
I have this problem in a project I'm working on: I have a list
This a data binding question in C#. I have a simple Person class: public
As a matter of fact you have smth like /java/src and /java/test . But
I have a star schema type data base, with fact tables that have many
I have basically succumbed to the fact that if you are a hardcore computer
I have some commits that I've decided, after the fact, are going to be
I have a rails app moving along fairly well, but the fact that I'm

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.