报错 咋办
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/cnns/Homework has been compiled by a more recent version of the Java Runtime (class file version 54.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(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
正在回答
问题原因:可能是在较低版本的JVM上运行较高版本的JDK编译的java class文件产生的错误。
解决办法:右击项目-->properties-->java compiler --> Enable project specific settings -->将compiler compliance level设置为与jvm一致的版本(jvm在命令行中java -version所显示的版本)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | import java.util.Scanner; public class Homework { // 插入数据 public int [] insertDate() { int [] array = new int [ 10 ]; int test; Scanner scan = new Scanner(System.in); // 循环插入数据 for ( int i = 0 ; i <= 8 ; i++) { System.out.println( "插入第" + (i + 1 ) + "位数字" ); test = scan.nextInt(); if (test == 0 ) { System.out.println( "输入的数据不能为零,请重新输入" ); i--; continue ; } else { array[i] = test; } } scan.close(); System.out.println( "数据为:" ); for ( int o:array) { System.out.print(array[o]+ " " ); } return array; } // 显示所有数据 public void showDate( int [] a, int length) { int [] array = null ; Homework b= new Homework(); array=b.insertDate(); System.out.println( "数据为:" ); for ( int o:array) { System.out.print(array[o]+ " " ); } } // 指定位置插入数据 public void insertAtArray( int [] a, int n, int k) { } // 能被3整除的数据 public void divThree( int [] a) { } // 提示信息 public void notice() { System.out.println( "*****************************" ); System.out.println( "1--插入数据" ); System.out.println( "2--显示所有数据" ); System.out.println( "3--在指定位置插入数据" ); System.out.println( "4--查询能被3整除的所有数据" ); System.out.println( "0--退出" ); System.out.println( "*****************************" ); System.out.println( "请输入对应的数字进行操作:" ); } // 主方法 public static void main(String[] args) { int [] array = null ; Scanner scan2 = new Scanner(System.in); Homework method = new Homework(); do { method.notice(); // 输入数字,选择功能 String n = scan2.next(); switch (n) { case "1" : array = method.insertDate(); break ; case "2" : method.showDate( null , 0 ); // break; // case "3": // method.insertAtArray(int[] a, int n, int k); // break; // case "4": // method.divThree(int[] a); // break; case "0" : System.out.println( "退出程序" ); System.exit( 0 ); default : System.out.println( "输入错误。" ); } } while ( 1 == 1 ); } } |
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧