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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:37:28+00:00 2026-06-15T10:37:28+00:00

Hi I am trying to deserialize the following object. public class Book extends Item

  • 0

Hi I am trying to deserialize the following object.

public class Book extends Item implements Serializable {
public Boolean isBook;
public Boolean isBookch;

private String publicationPlace;

private String publisher;

private int edition;

private String pages;

private String article;

Book(String title, String author, String year)
{
super(title, author, year);
    isBook = false;
    isBookch = false;
    publicationPlace = " !!! Not Known !!! ";
    publisher = " !!! Not Known !!! ";
    edition = 1;
    pages = "!!! Not Known !!!";
    article = " !!! Not Known !!! ";
}

this is structure of the object and I am serailizing it as ….

openw("books.dat");
        Date date = new Date ();
        out.writeObject(date);
        for(Book b : books )
            out.writeObject ( b );
        closew();

and this is working pretty much working fine with out any errors.
I am tryin to decentralize it as …

openr("books.dat");
        Date lastsaved = (Date)in.readObject();
        System.out.println("last saved date : " + lastsaved.toString());

        while( true )
        {
            Object o = in.readObject();
            if(o == null )
            break;
            else
            {
            addItem((Book)o);
            books.add((Book)o);
        }
        }
        closer();

and this is giving the error as : java.io.InvalidClassException: Book; no valid constructor

How to clear this problem.. thanx in advance…

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

    The class Item must implement Serializable as well,

    class Item implements Serializable {
    
        // ...
    
    }
    

    and it works!

    If however, Item is out of your reach and does not have a non-argument constructor, you cannot make Book serializable. The only way to make a subclass of a non-serializable class serializable is if a “subclass-accessible no-arg constructor of first non-serializable superclass” is found (quoting from the source code of ObjectStreamClass‘s getSerializableConstructor method). Which in your case seems to be missing, so Book cannot be made serializable.

    In which case, given your object consists of primitives only anyway, you could to look into JSON as an alternative way of serializing objects. There’s a list of JSON libraries for Java on http://www.json.org

     

    NB, how is it possible that Java can create objects of serializable classes without calling a constructor? There’s an unsafe method somewhere deep down in Java’s API that is used to allocate objects without calling their constructor. True story.

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

Sidebar

Related Questions

I get the following error when trying to deserialize an object in C#. Exception
I am trying to deserialize the following xml structure into an object... <?xml version=1.0
I have the following classes: [Serializable] public class ExtendedAddressData { public String AddressLine1 {
I am trying to deserialize a JSON string into a class instance in Haxe.
I'm trying to deserialize json to an object model where the collections are represented
I'm trying to make a genric code to serialize and deserialize any object that
I'm trying to deserialize the following XML document: <?xml version=1.0 encoding=utf-8 ?> <TestPrice> <Price>
I'm trying to use JSON.Net to deserialize a JSON object into a C# object.
I am trying to deserialize a Json object that I am getting from the
I'm trying to serialize and deserialize an array list with a object inside: HairBirt

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.