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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:26:50+00:00 2026-06-08T17:26:50+00:00

I have a program that calls a function, requestAudioBlocks to request some data. In

  • 0

I have a program that calls a function, requestAudioBlocks to request some data. In it, it initialises an array, then calls a request for the data.

private ReadAudioData[] receivedAudioMessages;

private int receivedMessageCount;

private boolean requestAudioBlocks(long blocksPerRequest)
{
    receivedAudioMessages = new ReadAudioData[2];

    receivedMessageCount = 0;

    connection.sendRequest();  //Send the command
}

When connection.sendRequest is run, connection.sendRequest calls saveAudioBlocks, sending it a variable download which is to be put into the array.

private ReadAudioData audioDataPacket;

public void sendRequest()
{
    ReadAudioData readAudioData;

    while (int count = 0; count < 2; count++)
    {
        readAudioData = new ReadAudioData();

        //Add the received information into the readAudioData variable

        audioDataPacket = readAudioData;

        saveAudioBlocks(audioDataPacket);
    }
}

Every time a new ReadAudioData object is received, saveAudioBlocks is called.

public void saveAudioBlocks(ReadAudioData download)
{
    receivedAudioMessages[receivedMessageCount] = download;

    receivedMessageCount++;
}

In the running of the program, saveAudioBlocks is called twice, which should put two ReadAudioData objects into the array receivedAudioMessages.

It works the first time, as the correct ReadAudioData object goes into receivedAudioMessages[0].

A ReadAudioData object has a variable String, which in this case is “111”. If you put a break point in saveAudioBlocks at the line receivedMessageCount++, you can look in the array and it contains the ReadAudioData object with String variable “111” as it should at location 0.

However, when saveAudioBlocks is called again with a new ReadAudioData object, if you look in receivedAudioMessages array at location 0, the ReadAudioData object is the new ReadAudioData object contained in the variable download passed to the function, which contains a String variable “122”.

It is almost as if I am saving a pointer to the variable download in the array and not the actual object as it currently is.

I have tried to use ArrayLists as well, but the same problem occurs.

I have a break point at saveAudioBlocks to ensure it is not being called are replacing the data when I am not aware and it is not.

Can anyone help?

  • 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-08T17:26:52+00:00Added an answer on June 8, 2026 at 5:26 pm

    It is almost as if I am saving a pointer to the variable download in the array and not the actual object as it currently is.

    This is what happens. You store the reference to the object that is referenced by the local variable download. So if properties of that object change, then the change becomes “visible” in your array too.

    Arrays do not store the objects themselves, they store references to objects.

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

Sidebar

Related Questions

I have a program that makes some hefty calls to the database and then
I have a program ( main.c ) that calls an external assembly function (
I have an AS3 program that calls a function multiple times. The function must
I have a program that constantly calls a function. In my function i use
I have an old Fortran77 program that calls a C++ function and passes several
I have the following code that calls the function uint32_pack. This program compiles with
I have a clojure program that at some point executes a function called db-rebuild-files-table
I have a program written in C++ with a main function that calls a
I have a program that calls a Filewatcher function, like this Main() { watch();
I have a C program which has a function call that is defined in

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.