Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocalDate has private access in LocalDate [duplicate]

Tags:

java

I am trying to find out someones age. I am following the answer given in here: How do I calculate someone's age in Java?

This is what I have so far:

public void setDOB(String day, String month, String year){

    LocalDate birthDate = new LocalDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
}

I am getting a an error when declaring the birthDate variable. I am getting the following error:

LocalDate(int,int,int) has private access in LocalDate

. I don't know what this error means but I am assuming its to do with data access (e.g. private, public, etc)

like image 935
Tarikh Chouhan Avatar asked Feb 12 '16 14:02

Tarikh Chouhan


People also ask

Is LocalDate immutable in Java?

LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed.

Can LocalDate be null?

It should not be null. Return value: This method returns LocalTime which is the parsed local date-time. Exception: This method throws DateTimeParseException if the text cannot be parsed.

What is the default value of LocalDate in Java?

LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd. We can use now() method to get the current date.


1 Answers

The constructor you are calling is private.

You need to call

LocalDate birthDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));

to construct your date.

like image 116
wero Avatar answered Sep 19 '22 11:09

wero