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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:17:14+00:00 2026-06-01T13:17:14+00:00

I am trying to serialize an ArrayList<Prescription> using an ObjectOutputStream Here is the Prescription

  • 0

I am trying to serialize an ArrayList<Prescription> using an ObjectOutputStream

Here is the Prescription class:

import java.io.Serializable;
import java.util.Calendar;

public class Prescription implements Serializable {

    private static final long serialVersionUID = 4432845389029948144L;

    private String name;
    private String dosage;
    private int originalQuantity = 0;
    private int quantityRemaining = 0;
    private String prescribingPharmacy;

    private long dateStarted = 0;

    private boolean taken_AM = false;
    private boolean taken_Noon = false;
    private boolean taken_PM = false;

    private boolean taken_Mon = false;
    private boolean taken_Tue = false;
    private boolean taken_Wed = false;
    private boolean taken_Thu = false;
    private boolean taken_Fri = false;
    private boolean taken_Sat = false;
    private boolean taken_Sun = false;

    public Prescription(){
        this.name = "Unknown";
    }

    public Prescription(String name, String dosage, int quantity, String pharmacy){
        this.name = name;
        this.dosage = dosage;
        this.originalQuantity = quantity;
        this.quantityRemaining = quantity;
        this.prescribingPharmacy = pharmacy;
        this.dateStarted = Calendar.getInstance().getTimeInMillis();
    }

    public void setTaken(boolean AM, boolean Noon, boolean PM){
        this.taken_AM = AM;
        this.taken_Noon = Noon;
        this.taken_PM = PM;
    }

    public void setTaken(boolean Mon, boolean Tue, boolean Wed, boolean Thu,
        boolean Fri, boolean Sat, boolean Sun){
        this.taken_Mon = Mon;
        this.taken_Tue = Tue;
        this.taken_Wed = Wed;
        this.taken_Thu = Thu;
        this.taken_Fri = Fri;
        this.taken_Sat = Sat;
        this.taken_Sun = Sun;
    }

    public String getName(){
        return this.name;
    }

}

Yet, when I try to do this, I get a NotSerializableException on the Prescription class. This doesn’t make any sense to me, as I am only using primitive data types and String.

Here is the function I am using to do the serialization:

public boolean saveToFile(){
    try {
        FileOutputStream fos = this.context.openFileOutput(LIST_SAVE_NAME, Context.MODE_PRIVATE);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(this.pList);
        oos.close();
    } catch(FileNotFoundException e){
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        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-06-01T13:17:15+00:00Added an answer on June 1, 2026 at 1:17 pm

    The code:

    public static void main(String[] args) {
        try {
            List<Prescription> d = new ArrayList<Prescription>();
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("C:\\temp\\Prescription.dat")));
            d.add(new Prescription());
            oos.writeObject(d);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    

    works without any exceptions with the class you posted, so there’s something you’re not telling us 🙂

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

Sidebar

Related Questions

I've got a public class, which implements Serializable, that is extended by multiple other
I'm trying to serialize a class in which I have a bitmap variable. Here
I'm trying to serialize a custom class that needs to use multiple elements of
I'm trying to serialize a type using the DataContractSerializer and am getting the exception
I was trying to serialize an ArrayList which contains custom objects. I'm serializing it
I've got a custom collection which adds functionality to the 'ArrayList' class. Here's some
class Json<T> { @SerializedName( T's type here ) private final ArrayList<T> _bucket = new
When I'm trying serialize a class containing this property: [NonSerialized] property System::Collections::ObjectModel::ReadOnlyCollection<String^>^ IgnoredWords I
I am trying to serialize my Report class info to an XML. At this
I am trying to serialize a C# object to JSON using JSON.net library. The

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.