• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

BufferedReader help

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem is that when i enter data, restart the program option #1 to add member option #2 to modify member, no matter what I do I only get back the first record. PLUS...if i dont enter anything the 2nd time, when I exit again..my member.dat file is erased! Do I need to structure the count differently in start_program?

 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If someone could just help me figure out this one section i think id be okay. I still have the problem of the member.dat file erasing itself when i hit exit, but while its created (ive seen it) if I have 4 names in it, i should be able to enter Member_id (when prompted)and that name come up. Only "one" does....just one. And the logic to me seems sound,...create an answer variable (modMember) and compare that to memId. If i hit Modify Member and it asks for a member id,....i should be able to do that again and again with different id's. Any help would be appreciated. Only one comes up and its ignoring all others.

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure exactly what you are trying to do. I assume that each member has a unique id? Then what you're describing seems like you want to keep looping asking for a member id until the user hits a value that indicates they are finished.
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a series of menus. The first on (in the Menu method) comes up and right now im only dealing with option #1, add/modify member. When that is called, a second menu comes up asking if you want to (1)add (2)modify (3)delete a member.

In the Modify_member, a list of names (last name, first name, member id..gender..etc) is created and in the exit method, written to member.dat.

When the program is run again, and i get to "modify member", option 2 under the second menu again, I want to be able to access any one of those names by their member id. I "can" access one,...only one. It for some reason ignores all the others.

I can do a search of my pc and find the member.dat file and see that it does create the list, but running it again only allows me to access one name. That is my problem.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this line.



If you look at the API, you'll see that the behavior you're describing about the file being deleted is exactly what that constructor of FileWriter does.
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it writes to that file. WHich it does, ive seen it. When i read that file in again, and go to select by ID, i can only read one name. Im not (at that point) writing again. If they are there, the way i have the selection set up, it keeps going back to the menu asking you if you want to (1)add or (2) modify and modify asks you to specify a member id. That list is still there (theoretically) why does it only acknoledge one?
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't it only acknowledge the one with the member id that you search for?
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, but then when it goes back to the (1)add (2) modify menu, i want to be able to search for another member.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want to append to "member.dat" or overwrite it? I think append is done like so:
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it SHOULD work,..i have an example from class,..the exit is coded just like that.
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somehow, through messing with the code, I lost what I had. It WAS printing names (God only knows how) now I get nothing but nulls. I guess im confused as to how i should (or should not) be passing count to this last method. All its supposed to do, is take the info gained in the menus i have going, and write it all to a file. No matter how i tinker with it, im getting Any advice on what I could try? Here is the complete exit_program method.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it outputting to string ok? How about your variable count, is that correct?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to distill this to a simpler program, and it works for me. I recommend that you do the same. Make a copy of your program and then distill it down to a skeleton prog that reproduces your error. One thing you have to be very careful with is the count variable. You are not getting it from Array.length so there is great risk of a mistake here. Also, I see that your for loop goes to i <= count, again a risk.


My guess is that if the problem isn't with the count variable it has to do with the arrays that you are passing to the exit procedure. How are you passing them? Can you do a System.out.println() check on one of the array variables at the time that you pass it to the exit routine (using a for loop to check each item in the array of course)?
[ April 08, 2007: Message edited by: pete stein ]
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a system.out.println for every variable (one whole line) in Exit_program. Everything is kosher "except" for Member_id, the only double. So hitting exit causes everything to print........for some reason if i do a search on the member.dat file and open it up in Notepad, i get nulls......Ive been debugging almost all day (nice Easter, eh) with no luck.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How big is your code?
 
RJ Cavender
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well,..thats kinda personal aint it? HAHA!! couple hundred lines,..but in manageable methods.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic