I have the following java method that reads a text file and creates new dots (coordinates in a graphic), however I am encountering the error of the title in reading the file. By following my stackTrace it points out that the error is when I try to read the first nextDouble (). Another curious thing is that sometimes it works normally, so I try to increase the number of points in my text file and it starts to freak out.
public void readDatabase(String s) throws FileNotFoundException{
try {
BufferedReader br = new BufferedReader(new FileReader(s));
String line = br.readLine();
Scanner trainFile = null;
while (line != null) {
line.trim();
trainFile = new Scanner(line);
double x = trainFile.nextDouble();
double y = trainFile.nextDouble();
int type = trainFile.nextInt();
this.database.add(new Ponto(x,y,type));
line = br.readLine();
}
trainFile.close();
br.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
Does anyone have any idea what the problem is?