Hi everyone,
I am using this method to read in a collection of ints and strings then converting the strings to numbers using the switch statement(as stated by my lecturer) and save it back into an array for further processing. However, everytime it gets to the line studentResponses[row][column] = scanner2.nextInt(); I get the error: java.util.InputMismatch exception: null (in java.util.Scanner). I have spent so long trying to figure out what could be causing this error to no avail so any guidance at all would be appreciated :)
public void readMarksData(String fileName, int numberOfStudents, int responsesPerStudent) throws FileNotFoundException
{
studentResponses = new int[numberOfStudents][responsesPerStudent];
File dataFile = new File(fileName);
Scanner scanner = new Scanner (dataFile);
cohort = scanner.nextLine();
int numberOfResponses = scanner.nextInt();
System.out.println (cohort);
System.out.println (numberOfResponses);
scanner.useDelimiter(",");
for (int row = 0; row < studentResponses.length; row++)
{
Scanner scanner2 = new Scanner(scanner.nextLine());
for (int column = 0; column < studentResponses[0].length-4; column++)
{
scanner2.useDelimiter(",");
**studentResponses[row][column] = scanner2.nextInt();**
}
System.out.print("\t");
for (int column = studentResponses[0].length-4; column < studentResponses[0].length; column++)
{
scanner2.useDelimiter("[ ]*(,)[ ]*");
String feedback = scanner2.next();
switch (feedback.toLowerCase())
{
case ("Excellent"): studentResponses[row][column] = 5;
break;
case ("Very Good"): studentResponses[row][column] = 4;
break;
case ("Good"): studentResponses[row][column] = 3;
break;
case ("Average"): studentResponses[row][column] = 2;
break;
default: studentResponses[row][column] = 1;
System.out.print(studentResponses[row][column]);
}
}
scanner2.close();
}
scanner.close();
}