简体   繁体   English

无法在Eclipse Helios中切换到编译器合规性级别1.8

[英]Can't switch to compiler compliance level 1.8 in Eclipse Helios

I am pretty new to eclipse and programming,Currently i am trying to learn java from a tutorial from caveofprogramming.com When i was trying to follow one tutorial based on switch an error keep disturbing me. 我是eclipse和编程的新手,目前我正在尝试从caveofprogramming.com的教程中学习java当我试图按照一个基于开关的教程时,一个错误让我感到不安。

import java.util.Scanner;

 public class App{

public static void main(String[] args){

 Scanner input = new Scanner(System.in);

 System.out.println("enter a number");

 String text = input.nextLine();

 switch(text) {

 case "start";

 System.out.println("Machine started");

 break; }  }   }

And it gives me an error on the switch command saying: 它给我一个错误的switch命令说:

cannot switch on a value of type string. 无法打开字符串类型的值。 only int values or enum constants are permitted 只允许使用int值或枚举常量

John Purcell at caveofprogramming.com suggested that its because of the compiler compliance level which is currently 1.4 and he said me to switch that to 1.8 but its not available there.1.6 is the last level which i can use. caveofprogramming.com的 John Purcell建议,因为编译器合规级别目前为1.4,他说我将其切换到1.8但是它不可用.1.6是我可以使用的最后一级。

Download and install the current Eclipse version . 下载并安装当前的Eclipse版本 Eclipse has a build-in Java compiler. Eclipse有一个内置的Java编译器。 Switching on String s was added in Java SE 1.7. 在Java SE 1.7中添加了开启String Java SE 1.4 is a very old version of Java. Java SE 1.4是Java的一个非常古老的版本。 It's not a good idea to learn programming using a version of Java which is that old. 使用旧版本的Java学习编程并不是一个好主意。

Also, as the other answer suggests, install the latest JDK. 另外,正如另一个答案所示,安装最新的JDK。

Your friend is correct in saying that it is because of a compiler compliance level. 你的朋友说这是因为编译器合规性水平是正确的。 In order to be able to fix your problem, your compiler must be version 1.7 or 1.8. 为了能够解决您的问题,您的编译器必须是版本1.7或1.8。 If you're using an IDE, you'll need to download a JDK to match up to whichever version you need (would recommend 1.8 as it's not EOL'd). 如果您正在使用IDE,则需要下载JDK以匹配您需要的任何版本(建议使用1.8,因为它不是EOL)。 If you're using Maven, you can change your compiler level by using the Maven Compiler Plugin . 如果您正在使用Maven,则可以使用Maven编译器插件更改编译器级别。

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

相关问题 Eclipse 中的编译器合规性级别 - Compiler compliance level in Eclipse 什么是Eclipse中的“编译器合规级别”? - What is “compiler compliance level” in Eclipse? 在Oracle JDK 8下运行Android Bundle / Eclipse Juno时没有Java 1.8编译器合规性级别 - No Java 1.8 compiler compliance level when running Android Bundle/Eclipse Juno under Oracle JDK 8 如何将默认的Eclipse Oxygen编译器合规性级别从9更改为1.8,而不是将其恢复为9? - How do I change the default Eclipse Oxygen compiler compliance level from 9 to 1.8 and not have it revert back to 9? Java-Eclipse编译器符合性级别1.6不能按预期工作 - Java - Eclipse Compiler Compliance Level 1.6 not working as expected 即使编译器合规性级别为1.6,Eclipse也会对枚举产生阻塞 - Eclipse chokes on enum, even though Compiler compliance level is 1.6 每次重新启动时,Eclipse都会将Java编译器的遵从性级别重置为1.7 - Eclipse resets Java compiler compliance level to 1.7 with every restart 为什么Eclipse抱怨项目指定了编译器遵从性1.8,但使用了JRE 11? - Why does Eclipse complain that the project specifies compiler compliance 1.8 but a JRE 11 is used? 指定的编译器合规性为 1.8,但使用了 jre 18 - the compiler compliance specified is 1.8 but a jre 18 is used 指定的编译器合规性为 1.6,但使用了 JRE 1.8 - The compiler compliance specified is 1.6 but a JRE 1.8 is used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM