If you are trying to execute the code outside your IDE...
The problem is Windows....
Open your command prompt and type "where java". When you do this, you will notice a "weird" path that looks something like this
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
I can't recall what Windows version introduced this shortcut, but I want to say it was Windows 7. The problem is that this shortcut points to a Runtime Environment that is more recent (newer) than the Java version that was used to compile the code. In other words, Java is backwards compatible; not forward compatible. Compiled code cannot run in a newer Java version.
How do you fix this?
One way is to go to your SYSTEM Environment Variables and edit the Path system variable and add JAVA_HOME at the very beginning of the paths. It will be something like this
%JAVA_HOME%; {YOUR OTHER PATHS HERE}
If you are trying to execute within the IDE, the problem is similar. POTENTIALLY, you can have a conflict between your PROJECT properties and your global IDE properties, where the Runtime Environment points to a newer version of Java than the JDK used to compile. That said...
I had a very weird issue with an application I worked on years ago. It was a client/server application and a coworker of mine was having this issue because, unbeknownst to her, there was version of the server running in the background that was causing the conflict. So, if you have a similar type of application, check your processes using Task Manager and make sure you either 1) shutdown this application and try again, or 2) Uninstall that application and reinstall the new one. In her case, she tried rebooting her PC but that didn't work because the process would start automatically after each reboot.