wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes OK, I am stumped Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "OK, I am stumped" Watch "OK, I am stumped" New topic
Author

OK, I am stumped

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Of course, why else ask for help, right? I have spent the entire weekend trying to figure out what I'm doing wrong.

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
>
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, the obvious question: what makes you think the ArrayList isn't being written to the file?


[Jess in Action][AskingGoodQuestions]
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
When I open it in a text editor the string of characters I entered into the fields do not exist. In other ArrayLists that I've written I can see the data in a text editor. Also, when I read the file back in (clipped portion of code) I display the file and nothing shows.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41102
    
  45
buttonSelected == "Save"

String comparison isn't done using the "==" operator, it's done using the "equals" method.


Ping & DNS - my free Android networking tools app
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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
Marshal

Joined: Mar 22, 2005
Posts: 41102
    
  45
Just to ask the obvious: "vehicleFile" is assigned a value somewhere? What, exactly, does the file contain after the program terminates?

That part of the code is working

It may work by chance, but it is a lingering bug that may get triggered one day.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Mike,

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!
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Thanks, that fixed it.

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OK, I am stumped
 
Similar Threads
DecimalFormat error
overloaded func, both accept same no and type of parameters
Problem passing variables
Is there a way to show an image in a JTable as a thumbnail?