-1

Lambda does not work with Android Studio:

This is what I have in gradle

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

These are the project settings

ext {

compileSdkVersion = 27
supportLibVersion = '27.1.0'
minSdkVersion = 27
targetSdkVersion = 27

}

This simple code is failing:

 button.setOnClickListener( (View x) -> Toast.makeText(
            getContext(), "Something", Toast.LENGTH_SHORT)
    );

The cause, that does not make any sense to me:

   --------- Cause ---------

java.lang.ClassCastException: Bootstrap method returned null

The fatal error:

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method

Java version: java -version java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

1 Answers1

0

Maybe your lamba is making issue, try it like this:

button.setOnClickListener(v -> Toast.makeText(
   getContext(), "Something", Toast.LENGTH_SHORT).show()
);
mmmatey
  • 666
  • 8
  • 15