Search code examples
javacompilationattributeslocaldate

Compilation problem with LocalDate attributes in Java?


I'm struggling to solve a problem in my code. In my classes, I have an attributes that are dates. When I try to compile my program, the errors say that it cannot find the symbol, with an arrow under the L on local date? I'm unsure how to proceed? Thankss

public class Adventure{
    private LocalDate startDate;
    private LocalDate endDate;

    public void Setdate(int year, int month, int day){
        this.startDate = LocalDate.of(year, month, day);
    }
    public LocalDate getStartDate(){
        return startDate;
    }
    public void SetDuration(int duration){
        this.duration = duration;
        endDate = startDate.plusDate(duration * 7);
    }
    public int getDuration(){
        return duration;
    }
    public LocalDate getEndDate(){
        return endDate;
    }
}  

Solution

  • If you have imported java.time.LocalDate and it still doesn't compile you are most using Java 7 or earlier. java.time was introduced in Java 8 as part of JSR 310.

    There is however a backport library for earlier Java versions. that you can add to your project.