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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:28:54+00:00 2026-05-16T16:28:54+00:00

For some reason when I deserialize my quotes ArrayList, I don’t get the right

  • 0

For some reason when I deserialize my quotes ArrayList, I don’t get the right object back. I want to make sure that whenever I read/write my object, it will always be the same object.

Serialization code:

private void serializeQuotes(){
        FileOutputStream fos;
        try {
            fos = openFileOutput(Constants.FILENAME, Context.MODE_PRIVATE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(quotes); 
            oos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch(IOException e){
            e.printStackTrace();
        }
    }

    @SuppressWarnings("unchecked")
    private void deserializeQuotes(){
        try{
            FileInputStream fis = openFileInput(Constants.FILENAME);
            ObjectInputStream ois = new ObjectInputStream(fis);
            quotes = (ArrayList<Quote>) ois.readObject();
            fis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch(IOException e){
            e.printStackTrace();
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
    }

Here is my Quote object

package org.stocktwits.model;

import java.io.Serializable;

public class Quote implements Serializable {

    private static final long serialVersionUID = 1L;

    public String symbol;
    public String name;
    public String change;
    public String percentChange;
    public String open;
    public String daysHigh;
    public String daysLow;
    public String volume;
    public String peRatio;
    public String marketCapitalization;
    public String yearHigh;
    public String yearLow;
    public String lastTradePriceOnly;

    public String getSymbol() {
        return symbol;
    }
    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getChange() {
        return change;
    }
    public void setChange(String change) {
        this.change = change;
    }
    public String getPercentChange() {
        return percentChange;
    }
    public void setPercentChange(String percentChange) {
        this.percentChange = percentChange;
    }
    public String getOpen() {
        return open;
    }
    public void setOpen(String open) {
        this.open = open;
    }
    public String getDaysHigh() {
        return daysHigh;
    }
    public void setDaysHigh(String daysHigh) {
        this.daysHigh = daysHigh;
    }
    public String getDaysLow() {
        return daysLow;
    }
    public void setDaysLow(String daysLow) {
        this.daysLow = daysLow;
    }
    public String getVolume() {
        return volume;
    }
    public void setVolume(String volume) {
        this.volume = volume;
    }
    public String getPeRatio() {
        return peRatio;
    }
    public void setPeRatio(String peRatio) {
        this.peRatio = peRatio;
    }
    public String getMarketCapitalization() {
        return marketCapitalization;
    }
    public void setMarketCapitilization(String marketCapitalization) {
        this.marketCapitalization = marketCapitalization;
    }
    public String getYearHigh() {
        return yearHigh;
    }
    public void setYearHigh(String yearHigh) {
        this.yearHigh = yearHigh;
    }
    public String getYearLow() {
        return yearLow;
    }
    public void setYearLow(String yearLow) {
        this.yearLow = yearLow;
    }

    public String getLastTradePriceOnly() {
        return lastTradePriceOnly;
    }

    public void setLastTradePriceOnly(String lastTradePriceOnly) {
        this.lastTradePriceOnly = lastTradePriceOnly;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((change == null) ? 0 : change.hashCode());
        result = prime * result
                + ((daysHigh == null) ? 0 : daysHigh.hashCode());
        result = prime * result + ((daysLow == null) ? 0 : daysLow.hashCode());
        result = prime
                * result
                + ((lastTradePriceOnly == null) ? 0 : lastTradePriceOnly
                        .hashCode());
        result = prime
                * result
                + ((marketCapitalization == null) ? 0 : marketCapitalization
                        .hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((open == null) ? 0 : open.hashCode());
        result = prime * result + ((peRatio == null) ? 0 : peRatio.hashCode());
        result = prime * result
                + ((percentChange == null) ? 0 : percentChange.hashCode());
        result = prime * result + ((symbol == null) ? 0 : symbol.hashCode());
        result = prime * result + ((volume == null) ? 0 : volume.hashCode());
        result = prime * result
                + ((yearHigh == null) ? 0 : yearHigh.hashCode());
        result = prime * result + ((yearLow == null) ? 0 : yearLow.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Quote other = (Quote) obj;
        if (change == null) {
            if (other.change != null)
                return false;
        } else if (!change.equals(other.change))
            return false;
        if (daysHigh == null) {
            if (other.daysHigh != null)
                return false;
        } else if (!daysHigh.equals(other.daysHigh))
            return false;
        if (daysLow == null) {
            if (other.daysLow != null)
                return false;
        } else if (!daysLow.equals(other.daysLow))
            return false;
        if (lastTradePriceOnly == null) {
            if (other.lastTradePriceOnly != null)
                return false;
        } else if (!lastTradePriceOnly.equals(other.lastTradePriceOnly))
            return false;
        if (marketCapitalization == null) {
            if (other.marketCapitalization != null)
                return false;
        } else if (!marketCapitalization.equals(other.marketCapitalization))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (open == null) {
            if (other.open != null)
                return false;
        } else if (!open.equals(other.open))
            return false;
        if (peRatio == null) {
            if (other.peRatio != null)
                return false;
        } else if (!peRatio.equals(other.peRatio))
            return false;
        if (percentChange == null) {
            if (other.percentChange != null)
                return false;
        } else if (!percentChange.equals(other.percentChange))
            return false;
        if (symbol == null) {
            if (other.symbol != null)
                return false;
        } else if (!symbol.equals(other.symbol))
            return false;
        if (volume == null) {
            if (other.volume != null)
                return false;
        } else if (!volume.equals(other.volume))
            return false;
        if (yearHigh == null) {
            if (other.yearHigh != null)
                return false;
        } else if (!yearHigh.equals(other.yearHigh))
            return false;
        if (yearLow == null) {
            if (other.yearLow != null)
                return false;
        } else if (!yearLow.equals(other.yearLow))
            return false;
        return true;
    }
}
  • 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-16T16:28:55+00:00Added an answer on May 16, 2026 at 4:28 pm

    Why don’t you delete the file in “serializeQuotes()” before writing the object. That way you will be sure, that there will be only one object there.

    private void serializeQuotes(){
             FileOutputStream fos;
             File file = new File(Constants.FILENAME);
             if (file.exists()) file.delete();
            try {
                fos = openFileOutput(file, Context.MODE_PRIVATE);
                ObjectOutputStream oos = new ObjectOutputStream(fos);
                oos.writeObject(quotes); 
                oos.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
    

    Or if you do not want to delete file every time, use some kind of iteration when reading obejcts from it.

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

Sidebar

Related Questions

I am trying to deserialize an nhibernate object. From some reason I am getting
For some reason there's a variable called d that is defined immediately after I
For some reason, my spec isn't passing. It appears that @categories isn't getting to
I'm not sure what's changed, but for some reason I'm getting a problem with
For some reason when I add removeUpdates() after the requestLocationUpdates() method, I don't obtain
For some reason I cannot get this to work for the life of me,
I have a JUnit test that is checking to make sure that a customized
For some reason, I can not click on links that are in animated divs.
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and

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.