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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:44:09+00:00 2026-06-13T10:44:09+00:00

Just did a brief reading to try and implement serialization into my code. Basically,

  • 0

Just did a brief reading to try and implement serialization into my code.

Basically, I have a Test class that holds a bunch of Questions. I would either like to serialize the whole Test object at once if possible, or if not each Question. Right now I am trying to do each Question.

public abstract class Question implements Serializable {
    ...
}

public class Test {

...

public void save() {
    try {

        System.out.print("File name will be saved.ser: ");

        FileOutputStream fileOut = new FileOutputStream("saved.ser");

        ObjectOutputStream out = new ObjectOutputStream(fileOut);

        for (Question question : questionList) {
            out.writeObject(question);
        }

        out.close();
        fileOut.close();

    } catch(IOException i) {
        i.printStackTrace();
    }
}

And then it gives this error:

java.io.NotSerializableException: java.util.Scanner
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at main.Survey.save(Survey.java:129)
    at main.MainDriver.main(MainDriver.java:59)

Is the problem that not every object in Question implements Serializable? Does that need to be done as well? That seems quite tedious, but I’ll do it if necessary. Do all of my classes that are used by Question, including it’s subclasses, need to be given that interface?

Also, would I be better off Serializing the whole Test object in my main method?

  • 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-13T10:44:10+00:00Added an answer on June 13, 2026 at 10:44 am

    Is the problem that not every object in Question implements Serializable? Does that need to be done as well?

    Yes, all members of a class that is serializable, must also be serializable.

    Do all of my classes that are used by Question, including it’s subclasses, need to be given that interface?

    No, if the super class is serializable, then all its sub classes are also serializable, implicitly. So, you don’t need to mark the sub classes as serializable explicitly again.

    In your case, I think Scanner object need not be a class member and can be a local variable where you are reading input. If you still need Scanner object to be a member variable, declare it as transient so that it is ignored during serialization and deserialization process.

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

Sidebar

Related Questions

just did my first test with MASM and FASM with the same code (almos)
I just did a quick test with UIScreen's +screens method, to see if the
I have the following test-class made on the fly: http://sumoin.pastebin.com/ff744ea4 No fine-tuning or something
I'm using git and Codebase for a project. I just did a test and
Ok, so I installed EF 4.2 from NuGet. Just did Install-Package EntityFramework. That's all
Please don't laugh at me but I believe that I just did something extremely
I just did git pull origin branch accidentally and now I have all these
I just did something terrible on a Git repo and I have no idea
I just did my first jQuery plugin which hides content that is too long.
Here is an xcode project that I just did to ask this question: http://www.mediafire.com/?z26ufsfhby62br9

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.