Java 不支持Lambda表达式-源代码1.7(Android Studio)

Java 不支持Lambda表达式-源代码1.7(Android Studio),java,android,Java,Android,我试图在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

我试图在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.
我正在使用JDK 1.8。

知道为什么会这样吗?任何资源


PS:堆栈中有两个类似的问题,但都没有解决这个问题。请先了解问题,然后再标记副本

看起来您需要将:
-source 8
作为参数传递给编译器。

以下是解决方案:

Android不能建立在JDK1.8上; 并且Lambda表达式不能在低于1.8的JDK中使用

解决方案是回到JDK1.7,避免使用Lambda符号。 代替使用:

button.setOnClickListener((v) -> {


                    Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
                    MainActivity.this.startActivity(newIntent);
                }
            });
我们必须这样做:

       button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                Intent newIntent = new Intent(MainActivity.this, NextActivity.class);
                MainActivity.this.startActivity(newIntent);
            }
        });

如何设置编译器参数?请阅读此。。。我的偏好与Windows中的不同,如链接所示。没有多大帮助。我使用Mac.Closing作为副本,特别是因为:“Android不支持Java 8。它最多只支持Java 7(如果您有kitkat),但它仍然没有InvokedDynamic,只有新语法sugar。”