I am trying to write out to an OOS, I get no errors, but the ArrayList doesn't get written out to the file, the entry counter does, but not the list. Below is a snippet of the code, let me know if you need anything else (there are three modules involved, so I'd rater post the files if possible).
Here is the code snippet
Here is the code that calls the above:
Here is the output from the run (I print out some of the field as show in the first snippet of code):
Thanks for help
Ulf Dittmer wrote:
buttonSelected == "Save"
String comparison isn't done using the "==" operator, it's done using the "equals" method.
That part of the code is working, otherwise my println commands wouldn't work.
Just tried something else, I put println commands (outputting the ArrayList) around the .add command and the output was exactly the same, seems the .add is the culprit.
Ulf Dittmer wrote:Just to ask the obvious: "vehicleFile" is assigned a value somewhere? What, exactly, does the file contain after the program terminates?
It does contain the value for entries, but the ArrayList is empty. When I tried doing a display of the 0 element I received an error stating something along the lines of a subscript out of bounds / array empty (sorry, don't remember the exact message).
That part of the code is working
It may work by chance, but it is a lingering bug that may get triggered one day.
I realize, and I will correct it.
I just noticed the problem: the members "type" and "record" are static, although they clearly are intended to be part of individual VIN objects. This means two things: first, it means that every extant VIN object has the same "type" and "record" values, since static members are shared by the whole class; and second, it means that "type" and "record" won't be stored into the file, since static members aren't serialized when you serialize an instance.
So although there may be -- nay, certanly are -- other issues, the first major change you need to make would be to remove the "static" qualifier from the declarations of these two members!
I realize there are problems with the code (it's not perfect), I do intend on cleaning it up. I am just learning Java, so I don't expect my code to be as polished as an experienced programmer. This is my 9th programming language (ignoring HTML and XML), so I feel that at 55 if I don't get things exactly right the first time I've earned enough stripes to be forgiven.