I was trying to run my android project in Android Studio, but I can't do so.
I am getting this error:
Error:(23, 47) error: lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
I am using JDK 1.8.
Any idea why is this happening? Any resoultion.
PS: There are couple of similar questions in Stack but none resolved this problem. Please understand the problem before you tag Duplicate.
Here is the solution:
Android cannot be build on JDK 1.8; And Lambda expression cannot be used in JDK below 1.8.
The solution is to go back to JDK 1.7 and avoid using Lambda sign. In place of using:
button.setOnClickListener((v) -> {
Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(newIntent);
}
});
We have to use this:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(newIntent);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With