Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Methods Don't Work

 
henri henri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1351
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The .ser files are not being written to the same folder as the .class files.....
 
henri henri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the .ser file gets written just as .ser with no name attached to it
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
henri henri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1351
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks, or perhaps I could use the same files that serialize on a simpler project to test them out first.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic