0
Why Scanner closed...?
java.lang.IllegalStateException: Scanner closed >ERROR> 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) C:\Users\WinDows\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds) //// https://code.sololearn.com/cHZ18h1tR1rL/?ref=app
5 Answers
+ 1
Remove line 58 info.close() and try again.
That should probably work.
+ 1
Make sure that your 'coursesLine' when split into 'courses' has only 3 values because your 'coursesNUM' is 3.
Something like this-
String coursesLine = "Java C++ Python";
String[] courses = coursesLine.split(" ");
for(String c:courses)
System.out.println(c);
OR remove the variable 'coursesNUM' and inside the for loop you can use courses.length to iterate.
0
Avinesh thank you, when i remove it other error appeared âArrayIndexOutOfBoundsException: 1â at line 23
0
Avinesh it dose not work but thank you
0
String coursesLine = info.nextLine();
String[] courses = coursesLine.split(" ");
System.out.print("The courses for this semester are:");
for (int i = 0; i < courses.length; i++) {
System.out.print(" " + courses[i]);
}
This can remove array index out of bounds exception.