1

enter image description here

I want to make the user able to search if he enters values for at least one of the fields given above. I captured the date selected from the JDateChooser as given below.

 String s = ((JTextField)searchOrderDateDateChooser.getDateEditor().getUiComponent()).getText();
 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//set the date format
 String datex = sdf.format(searchOrderDateDateChooser.getDate());

`

But this gives a NullPointerException if a date is not selected. How can I overcome this and make the user able to enter either one of the fields and search.

Aimee Borda
  • 842
  • 2
  • 11
  • 22
lasinicl
  • 161
  • 1
  • 11
  • 1
    you can apply a check on `s` `if(s != null)` then include that textfiled in the search else ignore it. – Muhammad Mar 10 '17 at 06:49
  • Even s is null i want to make the user able to search because he may have entered values for one of the other fields. But if s is null it gives a null pointer exception. I want to overcome that – lasinicl Mar 10 '17 at 06:55
  • where is your code for searching ? – Muhammad Mar 10 '17 at 07:00
  • Didn't write code for searching still. I want to overcome this exception and make it able search by clicking the search button even if the date is not selected. – lasinicl Mar 10 '17 at 07:10
  • you have to write two or more queries in order to do that and check each field if that is selected then run this else run the other query that is ignoring the date field. – Muhammad Mar 10 '17 at 07:20

0 Answers0