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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:43:07+00:00 2026-06-10T13:43:07+00:00

I need a way to save an ArrayList of objects. I have browsed similar

  • 0

I need a way to save an ArrayList of objects. I have browsed similar issues in the site and I (seem 😉 to have implemented what I found, but I get two problems:

  1. If I define the class as Serializable and put the constructor, it crashes at launch
  2. Otherwise, It does not save the array

Can you please help? I am developing code for a volunteer’s project and I am stuck…

Thank you a lot in advance.

My application has the following defined class: Globals (file Globals.java)


public class Globals extends Application implements Serializable {  

    private int position=-1;
    private ArrayList<RaccoltaPunti> raccoltePuntiList = new ArrayList<RaccoltaPunti>();
    public static final long serialVersionUID = 1L;
    /** constructor - seem required by Serializable, but creating it crashes app */
    public Globals(int position, ArrayList<RaccoltaPunti> raccoltePuntiList) {
        this.position = position;
        this.raccoltePuntiList = raccoltePuntiList;
    }
     // {getters and setters…}

    public void saveData(){

        String filename = getResources().getString(R.string.GLB_filename);
        String fileWithPath = this.getFilesDir().getPath().toString()+"/"+filename;
        Toast.makeText(this, "Salvataggio testo..."+ fileWithPath, Toast.LENGTH_LONG).show();
        try {
            FileOutputStream fos = new FileOutputStream(fileWithPath);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(this.raccoltePuntiList);    
            oos.close();
            Toast.makeText(Globals.this, "DatiSalvati ", Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            Log.e("FileSave", "CDM - IOException", e);
            Toast.makeText(this, "Errore saving file", Toast.LENGTH_LONG).show();
        }
    }
}

The class referenced is: RaccoltaPunti.java

public class RaccoltaPunti {

    private String nomeRaccolta;
    private String nomePromoter;
    private String numeroTessera;
    private Long puntiPusseduti;
    private String dataScadenzaPunti;
    private String sitoWeb;
    private String sitoWebUsername;

        // constructor, getters and setters…….
}

  • 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-10T13:43:08+00:00Added an answer on June 10, 2026 at 1:43 pm

    The problem seems resolved (now the file is successfully saved without errors and by manually opening it it seems to contain all the info).
    Thank you to you all.

    I summarise the solution for the benefit of any other future reader with the same issue.

    The problem was resolved by making the class RaccoltaPunti Serializable, as per following code fragment:

        import java.io.Serializable;
        ...
    
        public class RaccoltaPunti implements Serializable {
        ...
    

    I noted that RaccoltaPunti had already a constructor with parameters:

        public  RaccoltaPunti(
            String nomeRaccolta,
            String nomePromoter,
            String numeroTessera,
            Long puntiPusseduti,
            String dataScadenzaPunti,
            String sitoWeb,
            String sitoWebUsername) {
    

    For reference, the error reported in the log was referring to the line of code:

        oos.writeObject(this.raccoltePuntiList);    
    

    Regarding the constructor for the Globals class, my experiments showed that everything is working by just commenting it out. I did not try all possible combinations (i.e. with or without parameters): I just removed it.

    Thank you all who helped.

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

Sidebar

Related Questions

I've got a eclipse plugin ready, but now i need a way to save
I need a way to automatically format Date and Number objects based on locale
I have a simple program where I would like to save an arraylist to
i need a way to save a user chosen configuration composed of different parts.
What other ways than NSUserDefaults are there to save and get back Custom Objects?
I have a school work where I need to save an arbitrary image to
I have an ArrayList with custom objects. Each custom object contains a variety of
I need a save way to say: iOS, I want this method to be
I need to find the way to save images to the IsolatedStorage and show
I need to find the best way to record an audio stream. I have

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.