Short answer: Right-click on the class that contains the main method. Click on “Run As”. Click on “Java Application”. The keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press X; then release Shift and Alt and press J).
Long answer: To be honest, I am not 100% sure why this problem happens. It might be because of using a different jdk. I faced the same error. The solution was easier than I imagined. I was used to running my code using Ctrl + F11. But when I ran it as a java application (the way I described in “short answer”), the problem was resolved. I am not sure if it solves other people’s problems as well, but it is worthwhile to try. 🙂