Answer: Please right-click on a class that contains a main method. Click on the "Run As". Click on a "Java Application". A keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press the X; then release Shift and Alt and press the J).
Detailed Explanation: I am not 100% sure why above problem happens. It may be because of the use of a different jdk. I faced a same error. A solution was easier than I imagined. I was used to run my code using the Ctrl + F11. But when I ran it as the java application (the way I described in the "Answer"), my problem was resolved.
Hope it fixes your problem too!