This discussion is archived
3 Replies Latest reply: Sep 3, 2007 12:30 AM by 800322 RSS

serialization problems..

807605 Newbie
Currently Being Moderated
Hi. I am trying to implement serialization into my program but am having problems...

Basically, i think my data is serializing, but the reason that it is not deserializing is because of the following reason:

I have a class called Students, and it has a static variable called studentCount, and in my main method if I call the method viewAllStudents(), it will loop for as many times as the studentCount equals, but i dont think this count is being increased when i deserialize my students.....

Can anyone think of a way around this or how I can overcome my problem?

Many thanks
  • 1. Re: serialization problems..
    800322 Newbie
    Currently Being Moderated
    1) I can't solve your bugs by mindreading. Post your code. Formatted.
    2) Deserializing just to display data sounds a little silly to me.
    3) It doesn't sound to me like the static attribute is supposed to exist in the first place. Ask our datamodel instead.
    4) Consider serializing the whole collection of students.
  • 2. Re: serialization problems..
    807605 Newbie
    Currently Being Moderated
    Which part of the code should i post?

    Im not deserializing just to display data, its just im displaying the data to see if it is actually deserializing (anotherwords, displaying it is part of my testing to see whether it works). That static attribute is their as a count of how many students their actually is. I also am serializing the whole students, I have them in an ArrayList which gets serialized, and the reason I think it serialized properly is because if i go into the text file, i can see all the data (such as the student names etc).

    So basically, I think my data is serializing, but the static attribute that counts the amount of students isnt incrementing everytime a new student is added (which should increment when a new Student is created because in the constructor for student, i have studentCount++)

    My Programming tutor told me that it isn't display the data correctly because of the reason that the studentCount isn't incrementing, even though the data is actually being deserialized.....

    Perhaps their is a better way of counting my students rather than a static variable?
  • 3. Re: serialization problems..
    800322 Newbie
    Currently Being Moderated
    Which part of the code should i post?
    The part where you deserialize and try to update your variable.
    That static
    attribute is their as a count of how many students
    their actually is.
    Can't you just tell by looking at the data model? I mean, you have just provien how bad it is to have redundant information.
    I also am serializing the whole
    students, I have them in an ArrayList which gets
    serialized, and the reason I think it serialized
    properly is because if i go into the text file, i can
    see all the data (such as the student names etc).
    Serialization does not result in text files.
    So basically, I think my data is serializing, but the
    static attribute that counts the amount of students
    isnt incrementing everytime a new student is added
    (which should increment when a new Student is created
    because in the constructor for student, i have
    studentCount++)
    You are serializing, so the c'tor of course won't be invoked.
    My Programming tutor told me that it isn't display
    the data correctly because of the reason that the
    studentCount isn't incrementing, even though the data
    is actually being deserialized.....
    And your tutor can't be bothered to help you looking for your problem? It's his job.
    Perhaps their is a better way of counting my students
    rather than a static variable?
    I already told you - calling theArrayList.size() would be the best way.