Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Cannot resolve symbol of in LocalDate.of

import java.time.LocalDate;

public class Main {
    public static void main(String[] args) {
        LocalDate ld = new LocalDate.of(2000,10,20);
    }
}

I'm using IntelliJ IDEA Community Edition 15.0.3. When I try to use LocalDate.of it shows "Cannot resolve symbol 'of'". I tried typing "o" and then enter but it still doesn't work. When trying to compile and run it says:

"Error:(14, 37) java: cannot find symbol 
symbol:   class of
location: class java.time.LocalDate"
like image 239
Konrad von Jungingen Avatar asked Feb 23 '16 16:02

Konrad von Jungingen


People also ask

What does LocalDate of () do in Java?

LocalDate of() method in Java with Examples The of(int, int, int) method of LocalDate class in Java is used to create an instance of LocalDate from the input year, month and day of the month. In this method, all the three parameters are passed in the form of integer.

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 format of LocalDate?

LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd.

Is LocalDateTime immutable?

LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second. Other date and time fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. Time is represented to nanosecond precision.


1 Answers

Because of your new operator, you are attempting to instantiate a nested class called of within LocalDate, which does not exist.

Remove new so it can parse as the static method of within LocalDate.

LocalDate ld =  LocalDate.of(2000,10,20);
like image 137
rgettman Avatar answered Oct 02 '22 11:10

rgettman