I use Android Studio and recently got the error:
Error:Execution failed for task \':app:compileDebugJavaWithJavac\'. compileSdkVersion \'android-24\' re
I installed latest jdk but it was using the older one until I did this:
app rt-click >> module settings >> sdk location >> (old jdk path)
Replace the old JDK path with your new jdk path.
Works like a charm now :)