Java Compilation Errors: Unsupported Class Version

2019-07-20 07:34发布

I recently finished a project in Eclipse and it ran without a problem. Then recently I imported a new assignment to work on for class, but when I did my old project all of a sudden had a x on its icon. I looked through the code, nothing had been changed, but it threw this error in the console:

java.lang.UnsupportedClassVersionError at java.lang.ClassLoader.defineClass1(Native Method) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685)

And others. Is this possibly due to the version of java being used or something else?

1条回答
劫难
2楼-- · 2019-07-20 08:01

An UnsupportedClassVersionError is thrown when you use a higher JDK version to compile than when you try to run the program. For example, you compile Program.java using JDK1.7 but then attempt to run using JDK1.6. I am guessing that upon importing the new assignment for your class, you unknowingly adopted to use the JDK that the imported project was compiled in.

I suggest going to Eclipse Preferences and taking a look at your installed JRE's to make sure everything is okay and also to look at the projects Properties and looking at its Build Path. In general, make you you are using a version to run in that is at LEAST what you used to compile it. If you chose a higher version everything will still be okay.

EDIT: Here is a link for more information on the matter and where I had originally read about this. I knew I had saved the link somewhere. http://javarevisited.blogspot.com/2011/07/javalangunsupportedclassversionerror.html

查看更多
登录 后发表回答