ClassNotFoundException when deserializing a binary class file's contents

前端 未结 7 1702
[愿得一人]
[愿得一人] 2021-01-12 16:32

I don\'t know much about Java. I\'m trying to read a file containing an int and various instances of a class called \"Automobile\". When I deserialize it, though, the progra

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 16:59

    I fixed it in an easier way than the other answers -- my problem occurred when using the class in multiple projects.

    If you have multiple projects, make sure that the specific class you're deserializing is in the exact same path! That means, the same package names etc inside that project. Otherwise it won't find it and cause the ClassNotFoundException to be thrown.

    So if it's in

    /myPackage/otherPackage/Test.java

    Then make sure, that path is exactly the same in your other project.

提交回复
热议问题