0

I get a class not found exception when i rename the package from "default package" in java. When i run the code within the default package, the code works fine but when i paste the code into a new java project in eclipse and into a new package, there is a classnotfound exception thrown even when the class referred to above is clearly present in the new package. What is wrong? please help me :(

DEKE
  • 31
  • 3
  • by the way the classes in the new package are compiled fine – DEKE May 22 '11 at 19:17
  • -1 Because of absolute lack of even basic detail/information. I will +1 if this question is cleaned up (for future searching/viewing). See the comment by Mr. Skeet in his reply. –  May 22 '11 at 20:26

1 Answers1

3

My guess is that you're still trying to start the application with the existing application launcher, which is referring to the class in the "default" package.

Either create a new launcher, or edit the details of the existing one.

Of course, that's assuming you get the exception on launch. If that's not the case, you need to give us a lot more details.

EDIT: Okay, now you've posted the exception, it makes a lot more sense - you're trying to deserialize data which includes a reference to the class FaceBundle. Renaming classes breaks serialized data - it's as simple as that.

You can fiddle around with things in Java serialization, but I haven't done so myself. I suspect you'd want to create your own subclass of ObjectInputStream and override resolveClass.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • But still the classes before the one referred in the classnotfound exception are getting compiled without issues. Like the main class and a couple after that. The exception is thrown on the third class in the tree – DEKE May 22 '11 at 19:30
  • here is the error java.lang.ClassNotFoundException: FaceBundle at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) – DEKE May 22 '11 at 19:31
  • ..contd at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at java.io.ObjectInputStream.resolveClass(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) – DEKE May 22 '11 at 19:33
  • ..contd: at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at jrec2.EigenFaceCreator.readBundle(EigenFaceCreator.java:197) at jrec2.EigenFaceCreator.submitSet(EigenFaceCreator.java:151) at jrec2.EigenFaceCreator.readFaceBundles(EigenFaceCreator.java:112) at jrec2.TestFaceRecognition.main(TestFaceRecognition.java:25) – DEKE May 22 '11 at 19:33
  • No the launcher ain't the problem – DEKE May 22 '11 at 19:38
  • @DEKE Consider updating the original post with the details (Just the first ~6 lines of the exception) and removing these comments. Also explain when the exception occurs. (Also, note that `FaceBundle` is non-qualified here.) –  May 22 '11 at 20:17
  • @DEKE: It makes a lot more sense now you've included the stack trace. I don't know why you didn't say it was while you were trying to read data in the first place - we'd have got to the answer quicker. – Jon Skeet May 22 '11 at 20:21