11

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)

Romil Patel
  • 12,879
  • 7
  • 47
  • 76
Tarikh Chouhan
  • 425
  • 3
  • 5
  • 15
  • Your question is "I don't know what this error means but I am assuming its to do with data access (e.g. private, public etc)". I'm linking you to a post that explain in-depth the difference between those. Basically, you can't access a private constructor like that. – Tunaki Feb 12 '16 at 14:08
  • 1
    What puzzles me is: why is mi IDE showing me private constructors as method suggestions? – houcros Nov 25 '16 at 08:43

1 Answers1

27

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.

wero
  • 32,544
  • 3
  • 59
  • 84
  • 4
    `LocalDate.of` also accepts `int`, so it might feel more convenient to do `LocalDate birthDate = LocalDate.of(year, month, dayOfMonth)`. – houcros Nov 25 '16 at 08:42