Java – lambda expression – source 1.7 not supported (Android studio)
•
Android
See English answer > is it possible to use Java 8 for Android development? I tried to run my android project in Android studio, but I couldn't
I received 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 use JDK 1.8
Do you know why? Any regrouping
PS: there are several similar problems in stack, but this problem is not solved. Please understand the problem before marking duplicate
resolvent:
This is the solution:
Android cannot be built on JDK 1.8; And lambda expressions cannot be used under JDK 1.8
The solution is to return JDK 1.7 and avoid using lambda symbols. Instead:
button.setOnClickListener((v) -> {
Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(newIntent);
}
});
We must 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);
}
});
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码