0

[Fixed]

Thanks to @Visil below (accepted answer). I added the recommended code to build.gradle and waited after syncing gradle. The following popped up shortly after that...

enter image description here


Original Question

I am doing some Android programming with Android Studio 0.5.9, and I wanted to have some String switch statements. I set up everything, but the compiler is complaining that it cannot handle them.

String Switch-statements were introduced in JDK 1.7 so I am confused as to why I cannot do this.

Just to prove I am using JDK 1.7, you can check the image below... enter image description here

...also, my machine has JDK 1.8 installed... enter image description here

...what's up with this?


[UPDATE]

File >> Other Settings >> Default Settings

enter image description here

File >> Other Settings >> Default Project Structure

enter image description here

Build.gradle

enter image description here

Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58

1 Answers1

3

Please check your gradle source compatibilty configuration:

With Android KitKat (buildToolsVersion 19) you can use the diamond operator, multi-catch, strings in switches, try with resources, etc. To do this, add the following to your build file:

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

Note that you can use minSdkVersion with a value earlier than 19, for all language features except try with resources. If you want to use try with resources, you will need to also use a minSdkVersion of 19.

You also need to make sure that Gradle is using version 1.7 or later of the JDK. (And version 0.6.1 or later of the Android Gradle plugin.)

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1.7

visil
  • 400
  • 1
  • 3
  • 6