BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String fechaN;
System.out.println("Introduce tu fecha de nacimiento en el siguiento formato dd/mm/aaaa");
try{
fechaN = br.readLine();
SimpleDateFormat sdf = new SimpleDateFormat ("dd/MM/yyyy");
Date d = sdf.parse(fechaN);
Calendar fecha = new GregorianCalendar ();
fecha.setTime(d);
if(fecha.get(fecha.MONTH) == fecha.JANUARY){
System.out.println("El mes que escribiste fue Enero");
}else{
System.out.println("Es un mes distinto al que buscamos");
}
}catch(IOException ioe){
System.out.println("Error al leer datos");
}
The problem lies in the code "Date d = sdf.parse (dateN)" the parameter itself requests an object of type Date but I have seen that many make the change of String to date format in this way. The IDE logically tells me to cast it to Date Type "Date d = (Date) sdf.parse (dateN);" but then when I execute it it throws me an error of ClassCastException. I hope you can help me.