0

When i run the code below, the objIn.readObject(); throws a exception:

classNotFoundException project.Edge

The project.Edge is the object who i try to read from the file.

Object o = null;
ObjectInputStream objIn = null;
try {
    objIn = new ObjectInputStream(new FileInputStream("objects.dat"));
    o = objIn.readObject();
} catch (Exception ex) {
    ex.printStackTrace();
}
while (o != null) {
   //do stuff
}
2
  • 2
    The exception isn't strange, you should just call ex.printStackTrace() rather than System.out.println(ex.getMessage()); to see what it is. Commented May 17, 2016 at 9:34
  • readObject() only loads the data of a class, not the class itself. Therefore all classes used or referenced in objects.dat must be available in your project. Commented May 17, 2016 at 9:47

2 Answers 2

2

Maybe your project.Edge class not compiled correctly. Also check your classpath, this class must be available in your project.

Sign up to request clarification or add additional context in comments.

Comments

0

When you have this problem, check if the project.Edge is in the same package as when you write the binary file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.