0

i want to write a code using Runnable method using lambda operators but i got an error of Error:(40, 33) error: lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions) Here is my code:`

public void countDownStart(){
    handler= new Handler();
    runnable= (Runnable) () -> {
       handler.postDelayed((Runnable) this, 1000);
        try{
            SimpleDateFormat dateFormat= new SimpleDateFormat("YYYY-MM-DD");
            Date futureDate= dateFormat.parse("2017-03-31");
            Date currentDate= new Date();
            if (!currentDate.after(futureDate)){
                long diff = futureDate.getTime()- currentDate.getTime();
                long days = diff / (24 * 60 * 60 * 1000);
                diff -= days * (24 * 60 * 60 * 1000);
                long hours = diff / (60 * 60 * 1000);
                diff -= hours * (60 * 60 * 1000);
                long minutes = diff / (60 * 1000);
                diff -= minutes * (60* 1000);
                long seconds = diff / 1000;
             txtTimerDay.setText("" + String.format("%02d", days));
             txtTimerHour.setText("" + String.format("%02d", hours));
             txtTimerMinute.setText("" + String.format("%02d", minutes));
             txtTimerSecond.setText("" + String.format("%02d", seconds));
            }else{
                tvEvent.setVisibility(View.VISIBLE);
                tvEvent.setText("The Event Started");
                textViewGone();
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    };
    handler.postDelayed(runnable, 1 * 1000);
}
2
  • What is your JAVA verson? Commented Mar 30, 2017 at 10:49
  • have you searched the error message on google? Commented Mar 30, 2017 at 10:57

2 Answers 2

1

you are using java 7. lambda expressions are supported since java 8. problem in android is, only android n (7.0) or higher supports java 8. if you still want to use lambdas in lower android versions, you can use libraries like retrolambda, but these libraries often don't support all functionalities of java lambdas.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you added following instructions in your build.gradle file?

defaultConfig {

    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.