I'm unable to convert a String to a Date in Java and I just can't figure it out.
String sdate1 = "01/04/2016";
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
Date date1 = dateformat.parse(sdate1);
The last line causes an error, which forces me to surround it with a try/catch.
Surrounding this with a try/catch then causes the date1 to cause an error later on when trying to print the variable. The error states 'The local variable date1 may not have been initialized'.
Date date1;
try {
date1 = dateformat.parse(sdate1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
From some digging on the internet, I think that this suggests that the variable is failing the try. However, I cannot see how it could possibly fail.