[英]eclipse error, “Cannot switch on a value of type String for source level below 1.7”
I am new for eclipse, and could not find the solution for 我是新来的日食,找不到解决方案
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Cannot switch on a value of type String for source level below 1.7. 线程“主”中的异常java.lang.Error:未解决的编译问题:对于低于1.7的源级别,无法打开String类型的值。
I changed the Java Compiler from 1.6 to 1.8, but I still have this error. 我将Java编译器从1.6更改为1.8,但是仍然出现此错误。 The code is as below: 代码如下:
package learning;
import java.util.Scanner;
public class Switch {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Insert a command:");
String text = input.nextLine();
switch (text) {
case "start":
System.out.println("Game Started");
case "stop":
System.out.println("Game Stopped");
default:
System.out.println("Invalid Input");
}
input.close();
}
}
I just downloaded the latest eclipse and Java SED kit 8 yesterday. 我昨天刚刚下载了最新的eclipse和Java SED套件8。 Can anyone help me? 谁能帮我?
进入项目属性-> Java编译器...将合规级别更改为1.8
I have java 1.8, the following steps worked for me. 我有Java 1.8,以下步骤对我有用。
1) in eclipse.ini Change java version = 1.7 and launch eclipse, change java compiler settings as 1.7 1)在eclipse.ini中更改Java版本= 1.7并启动eclipse,将Java编译器设置更改为1.7
2) right click on the error, click change compilation settings. 2)右键单击错误,单击更改编译设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.