Reputation: 285
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.
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:
cannot switch on a value of type string. only int values or enum constants are permitted
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.
Upvotes: 3
Views: 7791
Reputation: 2582
Download and install the current Eclipse version. Eclipse has a build-in Java compiler. Switching on String
s was added in Java SE 1.7. Java SE 1.4 is a very old version of Java. It's not a good idea to learn programming using a version of Java which is that old.
Also, as the other answer suggests, install the latest JDK.
Upvotes: 1
Reputation: 81
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. 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). If you're using Maven, you can change your compiler level by using the Maven Compiler Plugin.
Upvotes: 0