aspose file tools*
The moose likes I/O and Streams and the fly likes Static Methods Don't  Work 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 "Static Methods Don Watch "Static Methods Don New topic
Author

Static Methods Don't Work

henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
The static methods used below do not get the values from the TextFields in my main class which are declared static. All code compiles, but does not work. I checked to see if the name retrieved was attached to the file extension .ser in the FileOutputStream constructor and there was not such file which proves that the text is not retrieved. There is something missing somewhere that is prventing the methods from retrieving the values in the other class called DVD_Titles



Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
Add println() statements to the code to display the strings and ints that are returned by the static methods. That'll show you what is being returned.

Where is the current directory when the program is executed? Is the file being written there?
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
I am using NetBeans and the .ser files that I have experimented with are printed in the main NetBeans folder. The .ser file is printed when I add a String name ("Willis.ser") instead of feeding it in via (name + ".ser"). It proves that the statice methods don't get the values from the textfields.
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
The .ser files are not being written to the same folder as the .class files.....
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
the .ser file gets written just as .ser with no name attached to it
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

You're showing us a main() routine, so I'm assuming that you're actually executing this class. And I see you're mentioned JTextFields, so I'll assume that those values are all supposed to come out of a GUI. But the very first line of main() asks this GUI for some value. Where do you actually create the GUI? Where does the user get time to type stuff in? Even if you are doing something scary and ugly like creating the GUI inside a static initializer someplace, this main() is still going to ask for the values and try to write a file long before the user gets a chance to type anything in. Am I missing something?


[Jess in Action][AskingGoodQuestions]
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
Thank you very much for your response.

The JTextFields are indeed part of a GUI in a JFrame. I want to serialize the information about a particular film typed into each TextField. The name of the film is supposed to serve as the .ser file name and the information is transmitted via a JavaBean called Film. When the user clicks on a JButton in the GUI, the SerializeFilm class is supposed to retrieve the data from each TextField, hence the use of the static methods of the main class. I have tested the program and the data is not even retrieved. I end up with a file called .ser instead having the name of the film attached to it. This shows that the data from the TextFields is not transmitted.

here is a link to show you what the GUI looks like.

http://pollscanada.com/screenshot.html
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
Thanks for your help. I see you are an author as well. I took at look at your book. This is my class that prints the film info and shows it in a JInternalFrame. I am a novice hobby programmer and find it very difficult to grasp some of the concepts.


Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
You need to try some debuggin techniques.
What do you see if you println() the following:
filmname, fGenre, fYear, fAudio, fLength, actors, name

What is shown on the screen?
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
ok thanks, or perhaps I could use the same files that serialize on a simpler project to test them out first.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Methods Don't Work