5

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.

Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125
kishoredbn
  • 2,007
  • 4
  • 28
  • 47
  • Closing as a duplicate, especially because of [this answer](http://stackoverflow.com/a/23318644/675383): _"Android does not support Java 8. It only supports up to Java 7 (if you have kitkat) and still it doesn't have invokedynamic, only the new syntax sugar."_ – nhaarman May 22 '15 at 18:23

2 Answers2

5

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);
            }
        });
kishoredbn
  • 2,007
  • 4
  • 28
  • 47
-2

Looks like you need to pass : -source 8 to the compiler as an argument.

user2260040
  • 1,275
  • 1
  • 13
  • 26