I have a JLabel with a date written as a String and I want to convert it into a sql.Date, but when I try to convert it, it run an exception. The date value is passed from a server with RMI.
Anyone know what could be the problem?
This is the RMI code:
PrenotazioniVaccini infoPrenotazione = null;
try {
infoPrenotazione = stub.getPrenotazioneVaccinazione(tf_Cf.getText());
} catch (RemoteException ex) {
ex.printStackTrace();
}
label_DataVaccino.setText(infoPrenotazione.getData());
This is the label code:
label_DataVaccino = new JLabel("");
label_DataVaccino.setBounds(0, 320, 400, 25);
label_DataVaccino.setHorizontalAlignment(JLabel.CENTER);
label_DataVaccino.setVerticalAlignment(JLabel.CENTER);
panel_AddVaccinatoGUI.add(label_DataVaccino);
This is where the Exception run:
private void registraVaccinato() {
String data = label_DataVaccino.getText();
Date dataVaccino = Date.valueOf(data);
System.out.println(dataVaccino);
}
And this is the error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException
at java.sql/java.sql.Date.valueOf(Date.java:141)
at centrivaccinali.AddVaccinatoGUI.registraVaccinato(AddVaccinatoGUI.java:294)
at centrivaccinali.AddVaccinatoGUI$3.actionPerformed(AddVaccinatoGUI.java:282)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
...
I've used this guide to convert a String into a sql.Date: https://www.javatpoint.com/java-sql-date
java.sql.Dateinstead of modern types, particularlyjava.time.LocalDate?