0

Error scanner closed ....?

i got this error and was unable to solve it. Please help me with this. Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at StudentsDistribution.MainProgram.TARTUP(MainProgram.java:29) at StudentsDistribution.MainProgram.main(MainProgram.java:103) public static void TARTUP(Scanner info,ArrayList sectionsList ) throws FileNotFoundException { int coursesNUM = info.nextInt(); // 3 int sectionsNUM = info.nextInt(); // 3 int studentsNUM = info.nextInt(); // 17 info.nextLine(); String coursesLine = info.nextLine(); String[] courses = coursesLine.split(" "); System.out.print("The courses for this semester are:"); for (int i = 0; i < coursesNUM; i++) { System.out.print(" " + courses[i]); } int sectionCapacity=0; sectionCapacity = (int) (Math.ceil((double) studentsNUM / sectionsNUM)); int remStud = studentsNUM; // intial value => needed for equally distribution for (int i = 0; i < sectionsNUM; i++) { // 3 iterations 1); // Section Object sectionsList.add(section); if (remStud >= sectionCapacity) { for (int j = 0; j < sectionCapacity; j++) { String studentID = info.next(); String FirstName = info.next(); String LastName = info.next(); Student student = new Student(studentID, FirstName, LastName, section.getSectionID()); section.addStudent(student); }

2nd Oct 2020, 8:25 PM
SH S
SH S - avatar
2 Antworten
0
Instead of passing Scanner object,make it class level object or static... For clarity share full code by this way... https://www.sololearn.com/post/75089/?ref=app
2nd Oct 2020, 9:22 PM
Jayakrishna 🇮🇳
2nd Oct 2020, 10:06 PM
SH S
SH S - avatar