This piece of code creates an infinite loop every time I run it. Can anyone see what's causing it? I know I have my own classes in there, but they are not causing the loop. Thanks in advance.
package fileinputPkg;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
import personPkg.Athlete;
public class AthleteFileInput {
private static ArrayList<Athlete> a = new ArrayList<Athlete>();
private String[] str;
public AthleteFileInput(){
try {
FileReader fread = new FileReader("data.txt");
Scanner parser = new Scanner(fread);
int j =0;
while(parser.hasNext()){
str = new String[4];
while (j < str.length) {
str[j] = parser.nextLine();
System.out.println(str[j]);
j++;
}
ArrayList<String> al = new ArrayList<String>();
for(int i=0;i<str.length;i++){
al.add(str[i]);
}
Athlete at = new Athlete(al);
a.add(at);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//default constructor
public String toString(){
return "Athlete File Input";
}//toString
}//AthleteFileInput

New Topic/Question
Reply



MultiQuote




|