I'm trying to convert a String to a Date variable in Java. To attempt to do so I'm trying a parse approach, which needs a try-catch block, but I'm having scope issues. The variable "date" in my Employee constructor isn't receiving the date, due to the date being in the try block. I receive the error: "date cannot be resolved to a variable". -- Please let me know your thoughts, or if I can convert the string to Date in an easier way. Thank you!
/Code Snippet/
String stringDate = sc.next();
SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy");
try {
Date date = dateFormatter.parse(stringDate);
}catch(ParseException e) {e.printStackTrace();}
e = new Employee(id, login, salary, date, name);