What I am trying to do is read from a file to an ArrayList and then display it using a JOptionPane. The only problem is the code i am having trouble with is in an ActionListener and I believe somehow I have created an infinite while loop because when I click the button the ActionListener is attached to, noting happens.
The .txt file I am trying to read from:
Mary Anne
A
Joe Wright
B
Andrew Heath
A
and the troublesome code segment:
public class ViewClassesListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
//entering the class and grade information into arrays
try
{
FileInputStream APStream=new FileInputStream("CompSciAP.txt");
DataInputStream APDIS = new DataInputStream(APStream);
BufferedReader APBR=new BufferedReader(new InputStreamReader(APDIS));
String temp="";
while ((temp=APBR.readLine()) != null)
{
//infinite loop?
CompSciAP.add(temp);
}
APStream.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
//displaying the information
stop=CompSciAP.size();
index=0;
while (index<=stop)
{
//or is this the infinite loop?
APLabel.setText(APLabel.getText()+CompSciAP.get(index)+"\n");
index++;
}
CompSciAPPane.showMessageDialog(All, APLabel, "Computer Science AP", JOptionPane.PLAIN_MESSAGE);
}
}
Please help me!