Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 325
user2408952 Avatar asked Aug 13 '14 09:08

user2408952


2 Answers

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
}
like image 199
ligi Avatar answered Nov 20 '22 16:11

ligi


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

like image 29
krunal patel Avatar answered Nov 20 '22 16:11

krunal patel