Ulf Dittmer wrote:For starters, the Profile.getProfile and School.getSchool methods do nothing. And the MyClassToBePersisted.setProfile and MyClassToBePersisted.setSchool methods do nothing either, and they're not even called by the SerializeMyClass class (which I think should happen, if I guess correctly what the code should do). So the answer to the question of why there's a NullPointerException is: Because "mySchool" is null, and the reason it's null is because the object that gets persisted never has a School (or a Profile) object set.
Ulf Dittmer wrote:You need the setter methods that you deleted. Think about this: What happens to the objects that are returned by School.getSchool and Profile.getProfile? Do they end up where you expect them to end up?
Ulf Dittmer wrote:How are you using the setter methods? If the school and profile fields of the MyClassToBePersisted object are null before you even serialize (and I suspect they are), then something is still missing.
If the school and profile fields of the MyClassToBePersisted object are null before you even serialize (and I suspect they are), then something is still missing.
Ulf Dittmer wrote:You only showed how you defined the setter methods, not how you're using them; in particular, which arguments are you passing to them?
And again:
If the school and profile fields of the MyClassToBePersisted object are null before you even serialize (and I suspect they are), then something is still missing.
Ulf Dittmer wrote:
Ulf Dittmer wrote:No, that's not what I meant. In your very first post you had these methods in your MyClassToBePersisted class:
You need to call those methods on your myClassToBePersist object, and you need to pass along the objects you get from the getSchool/getProfile methods. And, obviously, those setter methods need to do something - they need to store the objects you pass into them.
Ulf Dittmer wrote:You're getting closer, but you're still not calling the setSchool and setProfile methods of the MyClassToBePersisted class. You're calling the setProfile/setSchool methods of the Profile and School classes. Remember that the setSchool/setProfile methods of the MyClassToBePersisted class take a School/Profile object as parameter, not the individual values. Your code should look like this: