This error usually occurs after the upgrade of the lower version of Gradle. This is caused by the mismatch between the jdk version and the gradle. The solution is as follows:
Change the jdk version to version 1.8 in Project Structure -> SDK Location -> JDK Locaiton and recompile.