Any ideas why this isnt working?
DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
Date date1 = null, date2 = null;
String start, finish;
System.out.println("Please enter a start date:");
while(date1 == null){
try{
start = scan.next();
date1 = (Date) df.parse(start);
}catch(ParseException e){
System.out.println("Please enter a valid date!");
}
}
Im getting a classCastException
Exception in thread "main" java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date
I can't see the problem?
You're importing java.sql.Date instead of java.util.Date.
You have
import java.sql.Date
somewhere up top. Gotta be careful about the two Date classes; they aren't interchangeable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With