NoSuchElementException after closing

[ Interrupt a thread waiting for user input and then exit the app ]

I wanted to do the same exercise as mentioned in the above link. But, I ran into NoSuchElementException when I tried to use inConsole.nextLine(), after successfully closing BufferedReader object, in spite of reassigning inConsole like inConsole = new Scanner( to read from Standard input.

After closing BufferedReader object, can’t I reassign to Scanner object like above and use it?


Never close neither nor System.out. This will work and cause some strange effects. Actually you will never be able to read or write to SYSIN of SYSOUT respectively. Find other solution.

If you need advise how to solve your problem without closing please provide more information about lifecycle of your application and probably send relevant code snippets.

Leave a Reply

Your email address will not be published. Required fields are marked *