Edgar Buchvalov
Edgar Buchvalov

Reputation: 257

java datechooser how to get date

        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

Answers (2)

Dipesh Shrestha
Dipesh Shrestha

Reputation: 57

use this code, it worked for me ps.setString(1, ((JTextField)txtDate.getDateEditor().getUiComponent()).getText());

Upvotes: 0

Jon Skeet
Jon Skeet

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

Related Questions