aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes why won't it work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why won Watch "why won New topic
Author

why won't it work?

sigfrid sai
Greenhorn

Joined: Mar 23, 2011
Posts: 5
hi, I want to ask what's the problem with my program..
My program is about stacks, there's no error in it, but my problem is, our requirement is do all operations in stacks and then, even if you close the program, the next time you will open it, the previous data should still be displayed..
I used the filewriter and filereader, but every time I close it, then open it again, the previous data doesn't appear..
Any advice?
thanks.. here's my program.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

First of all, refactor your code to use a separate ActionListener for each button.

Don't let your class implement ActionListener. Instead do something like this:
It will be much easier for you to find your problem.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Howdy, Sigfrid!

Champ, I didn't test your program, but, at a first glance, the first thing that comes to my mind is, on line 41, when you are saving the content, try invoking out.flush() before invoking out.close() and let's see if it works.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Stephan van Hulst wrote:First of all, refactor your code to use a separate ActionListener for each button.

Don't let your class implement ActionListener. Instead do something like this:
It will be much easier for you to find your problem.


Agreed.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Oh and welcome to CodeRanch!
sigfrid sai
Greenhorn

Joined: Mar 23, 2011
Posts: 5
Stephan van Hulst wrote:Oh and welcome to CodeRanch!


thanks man,.
sigfrid sai
Greenhorn

Joined: Mar 23, 2011
Posts: 5
do I have to call the saveMe() and readMe() in every button?
if so, It still won't work.. sorry, I keep asking lots of question..
here's the code

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

When do you think your readMe method is called? Perhaps you could verify that (some simple debug statements (System.out.println will do) will verify if it is called at the right time (or ever)).


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
sigfrid sai
Greenhorn

Joined: Mar 23, 2011
Posts: 5
Andrew Monkhouse wrote:When do you think your readMe method is called? Perhaps you could verify that (some simple debug statements (System.out.println will do) will verify if it is called at the right time (or ever)).


I did what you said,.. the readMe method is called whenever i click a button..
then the saveMe method is called after I supplied what is needed.. I put a message dialog box to inform whenever these two methods are called, so it's a sure that they were called,. cause when i run the program, just like I said, they appeared before and after...
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

My apologies, wrong problem.

Looking at the "readMe" method - how many lines are in the file written to disk? How many lines are you trying to read?

What is the format of the file? Is the first number zero-indexed or ???

What happens if there are more numbers in the file than can be stored in the stack?
sigfrid sai
Greenhorn

Joined: Mar 23, 2011
Posts: 5
Andrew Monkhouse wrote:My apologies, wrong problem.

Looking at the "readMe" method - how many lines are in the file written to disk? How many lines are you trying to read?

What is the format of the file? Is the first number zero-indexed or ???

What happens if there are more numbers in the file than can be stored in the stack?


I'm sorry, I don't understand your question..
in the notepad, there's only one line..
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

sigfrid sai wrote:
Andrew Monkhouse wrote:Looking at the "readMe" method - how many lines are in the file written to disk? How many lines are you trying to read?

in the notepad, there's only one line..

Each pair of questions I asked is related to a different problem. But just on this one question, go back and look at your readMe method. Where is your call to "nextLine"? For that matter, where is the "id" variable defined? Where is your loop? Again - you might want to put debug statements in your method and in your loop and see what is being called when, and what the results are.

I left out some more important questions too - what are the constructors for the Scanner class? Is there a better constructor for you to use?

I know that this seems like we are only inching our way to a solution, but trust me - if you can get answers to these questions, you will be a long way to solving this (and future) problems yourself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why won't it work?