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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:15:49+00:00 2026-06-09T01:15:49+00:00

Given this code: public class TestSetup extends Object implements Serializable { // … some

  • 0

Given this code:

public class TestSetup extends Object implements Serializable {
   // ... some data and methods
}
ArrayList SetupArray = new ArrayList<TestSetup>();
// ----------------------------------------------
    public boolean readExternalStorageObjectFile(String filename, Object obj) {
    boolean isOk = true;
    try {
        File path = new File(sDirectoryPath + sTopDirectoryObj, filename);
        FileInputStream out = new FileInputStream(path);
        ObjectInputStream o = new ObjectInputStream(out);
        obj = o.readObject();
        o.close();
    }
    catch(Exception e) {
        Log.e("Exception","Exception occured in reading");
        isOk = false;
    }        
    return isOk;
}

// ----------------------------------------------
public void loadSetups() {
    this.SetupArray.clear();
    this.readExternalStorageObjectFile(SETUPS_FILENAME, this.SetupArray);
}

I would expect this.SetupArray in loadSetups() to contain existing array information that was read from readExternalStorageObjectFile(), but it doesn’t.

If I put a breakpoint in readExternalStorageObjectFile(), I see that obj does contain the ArrayList information when readObject() is executed.

But when it returns back to loadSetups(), this.SetupArray does not; it is empty.

I’ve tried to cast obj as ArrayList, but it’s the same result.

  • 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-09T01:15:51+00:00Added an answer on June 9, 2026 at 1:15 am

    The obj parameter is a pointer. If you reassign it with obj = o.readObject() you don’t modify the referenced data, you just reassign the pointer to another memory location.

    A solution would be to make the method return the object:

    ArrayList SetupArray = new ArrayList<TestSetup>();
    
    public Object readExternalStorageObjectFile(String filename) {
        try {
            File path = new File(sDirectoryPath + sTopDirectoryObj, filename);
            FileInputStream out = new FileInputStream(path);
            ObjectInputStream o = new ObjectInputStream(out);
            Object obj = o.readObject();
            o.close();
            return obj;
        }
        catch(Exception e) {
            Log.e("Exception","Exception occured in reading");
            return null;
        }        
    }
    
    public void loadSetups() {
        this.SetupArray = (ArrayList) this.readExternalStorageObjectFile(SETUPS_FILENAME);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code: public class MainActivity extends FragmentActivity implements ActionBar.TabListener { public static final
Given this code: public class Messager implements Runnable { public static void main(String[] args)
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
Given this code public interface IRepository<T> { IQueryable<T> GetAll(); } and this public class
given this code namespace GridTests { public class Grid<T> { IEnumerable<T> DataSource { get;
Given this Java code: class Account { private Integer number = 0; public synchronized
Given this code: class Base{ public: Base(); virtual ~Base(); }; class Derived: protected Base{
Given this code: public class Car { public virtual int CarId { get; set;
Given this snippet of code public abstract class Foo { private static SqlConnection _sqlConnection;
Given this code: class base { public: string foo() const; // Want this to

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.