I have a serializable class (CardGame) that I’m working with in Eclipse, and had originally put it in a package (x.cardlib). I renamed the package to y.cards.models using Eclipse’s refactoring utility (now that I know how to properly name a package).
I wrote a new class (CardGameDatabase) that downloads and converts serialized CardGames from a database, and wrote a new JUnit test case (CardGameDatabaseTest) for it later on. I tried to run my test case, and received the following error:
java.lang.ClassNotFoundException: x.cardlib.CardGame
at y.cards.database.CardGameDatabase.getGame(CardGameDatabase.java:28)
at y.tests.CardGameDatabaseTest.test(CardGameDatabaseTest.java:13)
I figured that I must still have a reference to the old package in my code, so I did a project-wide search for any and all references to the old package (e.g. “import x.cardlib.CardGame”). I didn’t find any.
I then deleted all compiled code and ran Eclipse’s cleanup utility, thinking that maybe an old reference existed in previously compiled code. I’m still receiving the error.
(Hm, I figured it out while writing, in fact. I’ll post the answer shortly in case anyone else has had a problem like this.)
Answer: I had stored the CardGame in my database before I refactored my code. Upon downloading the object from the database, it was still called x.cardlib.CardGame in the database. In short, renaming the package broke my serialization, leading to a ClassNotFoundException.