I'm having a problem with what I think is my FileReader. The point of the program at the moment is to allow a user to create an account (a User object) with instance variables of their user name and their password. The program should create a file that is called "user" and then the User's user number (the User objects are stored in an array) so then the FileReader can look for "userX", X being the number in the array. Then, the program would look for the password and user name, and then get the user to verify that they are in fact "userX" by entering their pass phrase and user name. I can't get my login thing to work properly. No matter how many accounts I create, it will always say that the login failed. I checked and the text file was there. Anyone know what is going on? Here is my code. I commented out one of the times where I told the JVM to set a variable because I wasn't sure where to put it. I'm pretty sure it is line 74.
Anyone know what is going on? I'm really confused.
[ March 29, 2008: Message edited by: Jacob Stein**** ] [ March 29, 2008: Message edited by: Jacob Stein**** ]
One thing I noticed is that you're comparing strings using the "==". That doesn't work. Strings are compared using the equals method.
Secondly, you're declaring tempName and tempPass twice, once as a static variable, and once as a local variable in the enterAccount method. I'm not sure if that causes problems in this case, but you should look into it.
Oh, .equals(), right? I forgot about that... I'll try that. Thanks a lot! [ March 29, 2008: Message edited by: Jacob Stein**** ]
Joined: Mar 28, 2008
Whoa... I just tried that and something went seriously wrong. I entered in all the information for user 0, and something didn't work. That wasn't so weird, but I tried copying and pasting the user name directly from the text file, including the little character that it takes "\n" as. That logged it in immediately, meaning that it skipped over my command to make it wait for user input. This is getting to be stuff that I'll admit I don't know very well. I've only made two programs with serialization and both of them I made with help from people who had at least a term in college Java. If someone could help me with this and explain too, I would be super duper awesomely grateful. Here is my updated code. I made no edits to the User constructor.
The logIn method doesn't deal with the case if someone enters neither a 1 or a 2. You might want to at least print out a warning message.
Also, in the makeAcccount method there are two consecutive assignments to numOfUsers; that looks suspicious.
By the way, the code does not perform anything that's generally referred to as "serialization"; do you mean file I/O? [ March 30, 2008: Message edited by: Ulf Dittmer ]
Joined: Mar 28, 2008
Sorry about the bad title. I had been up late the night before doing Flash, and then wrote that code that morning. You're right, it is file I/O. As for the consecutive assignments of numOfUsers, I now see that I meant to put userNum = numOfUsers so the program could have something to hold on to to remember that person's spot in the array. Then the numOfUsers is supposed to increment to make a spot for a new User in the array. I'll fix that, but I'm not sure if that has anything to do with the login constantly failing. Then again, it might so I'll go edit that right now. It didn't work, though I just noticed that in makeAccount(), I'm not loading numOfUsers. Could that have anything to do with my problem? I think I need to take a Java break. I've been making random programs for 6.5 hours on Friday, about 4 hours yesterday, and about an hour today. I've written about 700 lines of code over the weekend, and only 219 of them actually have a point. As an added bonus, I'm only in middle school, so my parents are actually here to scold me about sitting in front of the computer all day.