Android studio won't let me use a switch on a line?

I am creating an android application in android studio and trying to create a case of switching to a string. As far as I know, this is possible if you got a JDK of 7 or higher. I use the following /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home and still get an error when trying to include a line.

Does anyone know why he still fails, any help is appreciated.

EDIT: I get this eroor Error:(15, 16) error: strings in switch are not supported in -source 1.6 (use -source 7 or higher to enable strings in switch) so clear that somewhere in my project it uses JDK 1.6, but I can't figure out where.

+6
source share
2 answers

you will have to add this to your build.gradle (in the android section)

 compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } 
+10
source

Go to Project "Properties", then the Java compiler, check the box "Enable specific project settings"

you will get compiler matching settings by changing it to 1.7 and you can use the strings in the switch

+1
source

Source: https://habr.com/ru/post/973752/


All Articles