我上传了两个与我的 java 相关的屏幕截图。当我尝试编译 java 文件时,它会正确编译 java 文件并成功创建 .class 文件,但是当我尝试运行已编译的文件时,它会给出错误消息。我附上了两个与此问题相关的屏幕截图。请帮我。
这是我尝试使用java Test
命令运行的堆栈跟踪:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Test : Unsupp
orted major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessControll.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Test. Program will exit.
并使用java Test.java
命令:
Exception in thread "main" java.lang.NoClassDefFoundError: Test/java
Caused by: java.lang.ClassNotFoundException: Test.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessControll.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Test.java. Program will exit.