简体   繁体   中英

Changing compiler version in JAVA Eclipse results in alternating errors

In JAVA Eclipse, when I right-click on a project in the Package Explorer, select Java Compiler, and set "Compiler compliance level", "Generated .class files compatibility", and "Source compatibility" to 1.6, I get an error when I try to run my program:

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Multi-catch parameters are not allowed for source level below 1.7
    at cs567.hw10.BinTree.makeTopology(BinTree.java:204)
    at cs567.hw10.SmallParsimony.main(SmallParsimony.java:93)"

But when I follow the same procedure, but set the three conditions to 1.7, when I try to run my program, I get a different error:

"Exception in thread "main" java.lang.UnsupportedClassVersionError: cs567/hw10/SmallParsimony : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:698)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)"

I'm not experienced with using command line; that is why I am using Eclipse GUI. Thank you for any advice.

Basically, the combination of those two errors means you can't use multi-catch - ie catch (Exception1 | Exception2 | Exception3 e) - when you're going to run the code on a version of Java earlier than Java 7.

Either update the JRE you're running on to Java 7, or avoid using that particular bit of Java 7. (Some other language features such as the "diamond operator" may well be supported against earlier VMs; I haven't analyzed this in detail.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM