1

My app is not acknowledging JDK 1.8. I'm trying to use a switch case with a string as the switch. Just using a basic example from JavaDocs Yes, I could switch to if/else statements but I'd rather not.

public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
 String typeOfDay;
 switch (dayOfWeekArg) {
     case "Monday":
         typeOfDay = "Start of work week";
         break;
     case "Tuesday":
     case "Wednesday":
     case "Thursday":
         typeOfDay = "Midweek";
         break;
     case "Friday":
         typeOfDay = "End of work week";
         break;
     case "Saturday":
     case "Sunday":
         typeOfDay = "Weekend";
         break;
     default:
         throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);
 }
 return typeOfDay;
}

I'm getting the error of Incompatible Types: byte, char, int, short which would mean I'm using an old version of Java.. Which doesn't make sense as I have jdk1.8.0_11 installed.

Android Studio Version

Would this be an issue in my Gradle files?

apply plugin: 'com.android.application'

dependencies {
    compile 'com.parse.bolts:bolts-android:1.1.2'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')
    compile 'com.android.support:support-v4:18.0.0'
}

android {
    compileSdkVersion 15
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "name"
        minSdkVersion 15
        targetSdkVersion 15
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Black Bird
  • 797
  • 1
  • 10
  • 34

1 Answers1

1

Using this solution, I was able to get rid of the error. Add targetCompatibility to Java 1.7 to resolve this. Android does not currently use Java 1.8 in their projects.

Add this to the build.gradle file:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
Community
  • 1
  • 1
Black Bird
  • 797
  • 1
  • 10
  • 34