gpt4 book ai didi

java - java代码运行时错误

转载 作者:行者123 更新时间:2023-12-02 06:15:00 24 4
gpt4 key购买 nike

你好,我是java新手,我正在阅读一本书,其中有一个名为pharseomatic的代码,它基本上从单词列表列表中选择一个随机单词并打印到输出。

如下:

public class phraseomatic{
public static void main( String[] agrs){

String[] wordlistone = { "Hello ", "whats up ", "How ", " U doing " };
String[] wordlisttwo = { "I am ", " Am Interseted ", "Learning ", "Java" };
String[] wordlisttre = { "C sharp ", "C plus plus ", "C and Unix ", "Linux "};

int wlen1 = wordlistone.length;
int wlen2 = wordlisttwo.length;
int wlen3 = wordlisttre.length;

int rand1 = (int) ( Math.random() * wlen1 );
int rand2 = (int) ( Math.random() * wlen2 );
int rand3 = (int) ( Math.random() * wlen3 );

String phrase = " " + wordlistone[rand1] + wordlisttwo[rand2] + wordlisttre[rand3] ;
System.out.println("The Result is --->" + phrase );
}
}

我能够使用 javac Phenomatic.java 命令编译代码,一切都很好,但是当我使用命令 java Phenomatic 运行代码时,我得到以下输出或错误,请告诉我我是否正在这样做对还是我的代码已磨损或两者兼而有之......?提前致谢。错误如下:

 root@ubuntu:~/java# java phraseomatic 


Exception in thread "main" java.lang.UnsupportedClassVersionError: phraseomatic : Unsupported 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.AccessController.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)

最佳答案

代码编译时的java版本与运行时不同。指编译时使用的JAVA版本高于运行时的JAVA版本。请确保运行时jvm的版本低于编译时的版本。

关于java - java代码运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com