• Register
0 votes
631 views

Problem :

I am just a beginner in java coding.

Recently i got this error and was unable to solve it. Please help me with this.

exception in thread "main" java.lang.illegalstateexception: scanner closed

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution : 

To resolve the issue one must close the scanner and then

call nextInt on it 

calc c = new calc();

int a,b; 

System.out.print("Enter the first number:"); 

a=s.nextInt();

and your code will work

9 7 4
38,600 points

Related questions

0 votes
1 answer 792 views
792 views
Problem : I am getting the run time exception in my program while I am reading a file through a Scanner. exception in thread "main" java.util.nosuchelementexception: no line found
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 8 views
8 views
Problem: Please solve it … Because I am unable to find out the solution
asked Mar 14 Ifra 24.4k points
0 votes
1 answer 2 views
2 views
Problem: Scanner input = new Scanner(System.in); Could you give me a detailed explanation on what the code above is doing step by step? I don't really understand how it works
asked Mar 27 ummesalma 22.6k points
0 votes
1 answer 5 views
5 views
Problem: when I run the following code it shows an error that the scanner cannot be resolved to type. I checked that JRE is installed and the version is 1.7 what else do I need to check? please help.
asked Mar 27 ummesalma 22.6k points
0 votes
1 answer 1.8K views
1.8K views
Problem : I am trying to pass the values from the servlet to jsp page But when I run the page I am facing below error: Error as below : java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed org.apache.catalina.connector. ... getRequestDispatcher("usertaskpage.jsp"); dd.forward(request, response); But still I got a same error. How can I fix above error?
asked Feb 3, 2020 jwilliam 3.9k points
0 votes
1 answer 69 views
69 views
Problem : I am trying to run Java Applet and getting bellow error. java.lang.illegalstateexception: failed to create a child event loop
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 508 views
508 views
Problem : I got following exception from my servlet: java.lang.illegalstateexception: response has already been committed
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 14 views
14 views
The mess is with the second part of the program.
asked Feb 8 TeamScript 13.5k points
0 votes
1 answer 93 views
93 views
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( ...                     }                 }             }             System.out.println("The first distribution for students among the available sections");           }
asked Oct 2, 2020 sara s 120 points
0 votes
1 answer 2 views
2 views
Problem: Can anyone help me to understand how to read characters from a file in java using scanner?
asked 2 days ago ashik 10.7k points