Feb 28

I’ve got the new data structure in place now and finally am able to save and load it to a file.

Until yesterday, I was having a problem loading my data back in.  I’m using XStream to write out the Adventure structure as XML.  Writing it out was no problem, but when I loaded the data back in I kep getting a ClassCastException.  Doing a Google search for “xstream classcastexception” took me on journey through many forums and email lists with no clear solution in sight.  Did I need to write a custom ClassLoader?  Was something wrong with my Classpath?  I was starting to get bummed.

I asked a co-worker if he had ever used XStream.  He hadn’t, but offered to look at the problem with me sometime.  In preparation for that I decided to simplify the example so we could focus on the problem.  I whipped up a quick example class that created an Adventure, saved it and then loaded it.  I ran the program and it didn’t generate the ClassCastException!

After comparing the code between the two apps I noticed one thing I was doing in the real app that I wasn’t doing in the example after the data loaded - I was trying to assign the newly loaded data object as the input to a JFace TreeViewer, when I should been sending the object’s children.  That’s what was causing the ClassCastException.

So I never actually talked to my co-worker about the problem but was able to solve it.  I was explaining to my girlfriend who is called Rubber Ducking.

And I suspect that if I was using Unit Testing, I would’ve solved this problem a lot faster…


Comments are closed.