Java – won’t Android studio let me use switches on strings?
•
Java
I'm creating an Android Application in Android studio and trying to create a switch case on the string As far as I know, this is possible as long as your JDK is equal to 7 or higher I am using the following / library / Java / javavirtualmachines / jdk1 8.0_ 05.jdk/contents/home, and there is still an error when trying to open the string
Anyone knows why it still fails and any help is appreciated
Edit: I got this eroor error: (15,16) error: - string in switch is not supported in source 1.6 (use - source 7 or later to enable string in switch), so it obviously uses JDK 1.6 in my project, but I can't figure out where it is
Solution
You must add it to your build Gradle (enter the Android section)
compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码