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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:59:25+00:00 2026-05-31T22:59:25+00:00

Since DirectedSparseGraph implements serializable ( javadoc ), why can I not create a graph,

  • 0

Since DirectedSparseGraph implements serializable (javadoc), why can I not create a graph, serialize it to a file, then deserialize it? A “InvalidClassException” is thrown when deserializer.readObject() is called, with the message “no valid constructor”.

Looking at the javadoc and source files, it does have a zero-arguments constructor.

Is this a bug in the library? Or am I missing something? What type of constructor is Java expecting?

    DirectedSparseGraph graph = new DirectedSparseGraph();

    FileOutputStream underlyingStream = new FileOutputStream("output/temp.jung");
    ObjectOutputStream serializer = new ObjectOutputStream(underlyingStream);
    serializer.writeObject(graph);
    serializer.close();
    underlyingStream.close();   

    FileInputStream underlyingStream2 = new FileInputStream( "output/temp.jung" ); 
    ObjectInputStream deserializer = new ObjectInputStream( underlyingStream2 );
    DirectedSparseGraph loadedGraph = (DirectedSparseGraph) deserializer.readObject(); //EXCEPTION THROWN HERE
    deserializer.close();
    underlyingStream2.close();

Exception:

Exception in thread "main" java.io.InvalidClassException: edu.uci.ics.jung.graph.DirectedSparseGraph; edu.uci.ics.jung.graph.DirectedSparseGraph; no valid constructor
at java.io.ObjectStreamClass.checkDeserialize(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at gui.GraphViewer.main(GraphViewer.java:39)
Caused by: java.io.InvalidClassException: edu.uci.ics.jung.graph.DirectedSparseGraph; no valid constructor
at java.io.ObjectStreamClass.<init>(Unknown Source)
at java.io.ObjectStreamClass.lookup(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at gui.GraphViewer.main(GraphViewer.java:33)
  • 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-31T22:59:26+00:00Added an answer on May 31, 2026 at 10:59 pm

    The only requirement on the constructor for a class that implements
    Serializable is that the first non-serializable superclass in its
    inheritence hierarchy must have a no-argument constructor

    Source: http://www.jguru.com/faq/view.jsp?EID=251942

    During deserialization, the fields of non-serializable classes will be
    initialized using the public or protected no-arg constructor of the
    class. A no-arg constructor must be accessible to the subclass that is
    serializable. The fields of serializable subclasses will be restored
    from the stream.

    Source: http://docs.oracle.com/javase/1.5.0/docs/api/java/io/Serializable.html

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

Sidebar

Related Questions

Since hist() of the base R does not report percentages (and the freq=FALSE) does
Since i'm not strong in asp.net, probably my question will sound silly. I've got
Since yesterday suddenly my Eclipse does not work anymore. The error is Failed to
Since in the control file I have to provide a name (hard-coded) I need
Since OpenGL ES 2.0 is not backward-compatible to OpenGL ES 1.x because of it's
Since i could not get an exact answer on this question Distance of wgs
Since i can access private variables of an inner class directly and ... the
Since this morning I can't get one of my pages working. The error message:
Since Java char is 16 bit long, I am wondering how can it represent
Since I am not getting anywhere with my previous question , I would like

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.