Parsing date and running into a 'static reference to the non-static method' Error in java
date-format, java, non-static
Solution
`parse()` is not a static method. It's an instance method. You need to create a DateFormat instance, and then call `parse()` on this instance:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date gameDate = dateFormat.parse(scanner.nextLine());
A static method belongs to a class. It doesn't make sense to call `Person.getName()`. But it makes sense to call
Person pureferret = new Person("Pureferret");
String name = pureferret.getName();
Problem
I have a line in my main like so: ``` Date gameDate = DateFormat.parse(scanner.nextLine()); ``` Essentially I want to scan in a date with util.Scanner Which hits the error: Cannot make a static reference to the non-static method parse(String) from the type DateFormat Now, I've looked in to this error, but it doesn't seem as clear cut as this example. How do I get round this?