我试图在 Android Studio 中运行我的 android 项目,但我不能这样做。
我收到此错误:
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.
Run Code Online (Sandbox Code Playgroud)
我正在使用 JDK 1.8。
知道为什么会这样吗?任何决议。
PS:Stack 中有几个类似的问题,但没有一个解决了这个问题。请在标记重复之前了解问题。
这是解决方案:
Android 不能在JDK 1.8上构建;并且 JDK 1.8 以下不能使用 Lambda 表达式。
解决方案是回到 JDK 1.7 并避免使用 Lambda 符号。代替使用:
button.setOnClickListener((v) -> {
Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(newIntent);
}
});
Run Code Online (Sandbox Code Playgroud)
我们必须使用这个:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(newIntent);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6525 次 |
| 最近记录: |