Hello, Everyone, I am currently learning Java. As a beginner, I worked with console IO. To read input from the terminal, I use the Scanner class.

I tried a mini CLI project, so I used the Scanner object in different classes. For resource management, the Scanner object — especially when reading from sources like System.in or files — utilizes underlying system resources (like file descriptors or input streams). Closing the Scanner explicitly releases these resources back to the operating system, preventing resource leaks.

So, I closed the Scanner in each class, but after running my program, I got this exception:

Exception in thread "main" java.util.NoSuchElementException

This was the first time I saw this exception. After reading some related S…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help