Reputation: 77
I am building a java GUI which asks the user to type in his user id and if I find a match in my text file list, then I display his info to the GUI panel. If his id is not found, then I display a prompt to ask him to type in his id again.
The program I am having right now is that every time after I type in a wrong id, even if the next id I type in is a correct one, I could not display the right info to the screen. My GUI stays at that "wrong id" sate forever. I spent hours trying to figure out what went wrong but I just could not find it. Any help would be appreciated!
private class okButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
FileReader fr = null;
try{
fr = new FileReader("charList.txt");
}
catch (FileNotFoundException e1){
e1.printStackTrace();
}
BufferedReader bf = new BufferedReader(fr);
userID = Integer.parseInt(idField.getText());
while(line != null){
try{
line = bf.readLine();
}
catch (IOException e1){
e1.printStackTrace();
}
if (line != null){
fields = line.split("\t");
if (userID == Integer.parseInt(fields[0])){
System.out.println(fields[2]);
displayFieldsSelections();
resetFields();
break;
}
}
}
if (userID != Integer.parseInt(fields[0])){
mistakeResetFields();
}
}
}
Upvotes: 0
Views: 1901
Reputation: 712
I think the problem is that you are not declaring line
locally. In the beginning of the method try declaring line
.
Upvotes: 1