Java – IntelliJ switch statement uses string error: use – source 7
I tried to use IntelliJ (on Mac OS X) to compile some code I wrote using eclipse I tried to run the following code:
switch (category) {
case "below 20":
below20++;
break;
case "20 to 29":
to30++;
break;
case "30 to 39":
to40++;
break;
case "40 to 49":
to50++;
break;
case "50 to 59":
to60++;
break;
case "60 to 69":
to70++;
break;
case "70 t0 79":
to80++;
break;
case "80 to 89":
to90++;
break;
case "90 to 99":
above90++;
break;
default:
break;
}
However, I received an error:
java: strings in switch are not supported in -source 1.6 (use -source 7 or higher to enable strings in switch)
I know some answers will be: rtfe (i.e. replace manual and error) But I didn't I've tried the following:
>Preferences > compiler > java compiler and add - source 7 and / or - target to additional command line parameters > edit configuration: check to use alternative JDK and write to the directory / library / Java / javavirtualmachines / jdk1 7.0_ 51.jdk/Contents/Home
It hasn't been repaired yet What on earth did I do wrong?
Note: I know this is obvious because the directory is above, but I do have Java 7.0 installed
Thank you in advance!
Solution
In IntelliJ idea, you should also go to project settings – > project and set the appropriate project language level
