Hmmm. That error message is generally only going to come up in weird situations in which a class implements the Serializable interface, objects of the class are serialized, the class is then modified to not implement Serializable, and then you try to deserialize the contents of the file. Given that you're trying to extract Integers from the file, though, that explanation doesn't make sense, since it only applies if you're deserializing a user-supplied class.
So... how did you create the file foo.ser? What's really in it?
Ernest Friedman-Hill wrote:That error message is generally only going to come up in weird situations in which a class implements the Serializable interface, objects of the class are serialized, the class is then modified to not implement Serializable, and then you try to deserialize the contents of the file.
OK, that explains it, then! You saved a SaveBox in the file, and so Java is going to look for a class file named SaveBox to load when the file is read. But the SaveBox it finds when the class is read is not serializable, so this isn't going to work! You need to do two things differently:
1) To load foo.ser, you need SaveBox.class to exist, and (most importantly!) it needs to be the same class that was saved into the file -- i.e. the second one you showed me. Therefore, you're going to have to name your file reading class something else!
2) Once you fix that problem, your program will still fail. That's because you wrote a SaveBox, but you're trying to read two Integers. You need to read a SaveBox instead. Whatever you write ot the file, that's what you're going to get back out. So...
Your SaveBox class doesn't have getWidth and getHeight -- you'll need to add those.
Ernest, Thanks for your help. I think I understood what you said. Here are the two updated files based on your comments. I'm still getting an error on lines 25 and 26 saying that it can't find the symbol svbox. The program is giving errors when I run it in NetBeans.
Thank you for your help. O.K., I've declared the go method to take a SaveBox parameter. below is the code. Now I'm getting an error at runtime: "java.io.InvalidClassException: savebox.SaveBox; local class incompatible: stream classdesc serialVersionUID = -9024886691042451633, local class serialVersionUID = -1451760072563593720"
Also it's printing out that width and height are both = 0. They were set as 20 and 50 when I saved SaveBox.