I'm creating a android app in android studio and trying to create a switch case on a string. As far as i know this is possible, as long as you got a JDK equals to 7 or higher. I'm using the following /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
and still gets an error when trying to switch on a string.
Anyone knows why it 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 clearly somewhere in my project it uses JDK 1.6 but i can't figure out where.
you will have to add this to your build.gradle ( into the android section )
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
Go to Project "Properties" then Java Compiler , check the "enable project specific settings"
you will get the compiler compliance settings change it to 1.7 and you will be able to use strings in switch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With