I am trying to read via Scanner class two sets of patient data from a text file. Then save it to my RefUnsortedList. When i have 1 set of data, it works seamlessly. But when i add the second data right underneath, it gives me a InputMismatchException. It reads 4 out of 5 of the second set of data, then craps out when reading the fifth. System.out.println("Please enter Filename:"); String NewString = keyboard.nextLine(); File KeysFile = new File(NewString);
RefUnsortedList<Patient> NewList = new RefUnsortedList<Patient>();
Patient entry1;
String name1 = null;
String id1 = null;
String address1 = null;
int height1 = 0;
double weight = 0.0;
int count = 0;
try {
Scanner A1 = new Scanner(KeysFile);
while(A1.hasNextLine())
{
name1 = A1.nextLine();
id1 = A1.nextLine();
address1 = A1.nextLine();
height1 = A1.nextInt();
weight = A1.nextDouble();
entry1 = new Patient(name1, id1, address1, height1, weight);
NewList.add(entry1);
}
System.out.println(NewList.toString());
A1.close();
System.out.println(count);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
Here is my textFile:
Luis Shinin
0001
150-68 Foch blvd, Jamaica Ny, 11434
65
165
Tom No
0002
150-68 Arsenal place, wood ridge Ny, 11434
78
189
Thanks.