简体   繁体   English

似乎无法让我的Java在VS Code中工作

[英]Can't seem to get my Java to work in VS Code

I have been trying to get VS Code to work and compile my Java code. 我一直在尝试让VS Code工作并编译我的Java代码。 I have finally given up trying to fix it myself. 我终于放弃了尝试自己修复它。

I can't compile my code, I can't run it. 我无法编译我的代码,我无法运行它。 I don't even know what's wrong with it. 我什至不知道这是怎么回事。 I really want to use VS Code because it's so clean and versatile (so please don't recommend me other IDEs). 我真的想使用VS Code,因为它是如此干净和通用(所以请不要向我推荐其他IDE)。

Here is my code: 这是我的代码:

class DataStruct {
    Run|Debug
    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

(Manually transcribed from this image .) (从该图像手动转录。)

Here are my system variables: 这是我的系统变量:

系统变量

This is what I get: 这是我得到的:

PS C:\Users\SvenH\AppData\Roaming\Code\User\java-ws> cd "c:\Users\SvenH\AppData\Roaming\Code\User\java-ws\" ; if ($?) { javac DataStruct.java } ; if ($?) { java DataStruct }
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: DataStruct has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
PS C:\Users\SvenH\AppData\Roaming\Code\User\java-ws>

Make sure you are compiling and using the same java version. 确保您正在编译并使用相同的Java版本。
One simple way to do it is: 一种简单的方法是:

  • uninstall JDK and JRE 卸载JDK和JRE
  • download JDK and JRE, both at the same version 下载相同版本的JDK和JRE
  • install them 安装它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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