Reputation: 257
DateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
String nowYYYYMMDD = new String( dateformatYYYYMMDD.format( dateChooser.getDate()) );
textField_1.setText(nowYYYYMMDD);
i tried this way but i cant get date from datechooser error:
java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1032)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:785)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:778)
at java.text.DateFormat.format(DateFormat.java:314)
at Remontas.jbInit(Remontas.java:239)
at Remontas.<init>(Remontas.java:176)
at Remontas.main(Remontas.java:161)
Upvotes: -3
Views: 4399
Reputation: 57
use this code, it worked for me ps.setString(1, ((JTextField)txtDate.getDateEditor().getUiComponent()).getText());
Upvotes: 0
Reputation: 1503859
My guess is that dateChooser.getDate()
is returning null, given the stack trace. We can't tell why that is from the code you've given us.
Note that you're calling this from your Remontas
constructor - is that deliberate?
Upvotes: 1