On Apr 22, 8:14 pm, Adam Smith <[email protected]> wrote:
> I'm having a problem with my one transient integer, yearStarted. For some
> reason, it continuously returns a '0' (instead of the desired integer).
>
> public MyClassToBePersisited(School school, Profile profile) {
First, do not give parameters to your class constructor, as you cannot
serialize them. And inside the constructor, just assign new objects to
the private parameters. This way, you will have an object that is
completely self-contained and therefore can be serialized and
deserialized without loss of data.
> this.school = School.getSchool("", 23);
> this.profile = Profile.getProfile("TEST2", 77, "beach");
> }
Then in the same class define accessor for reading the parameters of
each parameter, and use them in another public method which will
display them. And you need also accessor in the School and Profile
classes.
The serialization/deserialization process has to be viewed like a
cascade of reading completely self-contained objects, and each object
should contain methods to access the objects contained in it, etc.
Hopefully it is clear for you.
>
> From what I understand, transient fields are not 'serialized'. Therefore,
> when I deserialize it, it automatically returns a '0'. How the heck can i
> get this to work? I've been working on this for days now.
>
> // Deserialize the previously saved
> // PersistentTime object instance.
> MyClassToBePersisited myPers = null;
> FileInputStream fis = null;
> ObjectInputStream in = null;
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---