java - Null Pointer Exception from JCalander Combobox -
my java application produces null pointer exception jcalander combobox. tried catch error. didnt work. can assist me fix this. please.
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception @ java.util.calendar.settime(calendar.java:1106) @ java.text.simpledateformat.format(simpledateformat.java:955) @ java.text.simpledateformat.format(simpledateformat.java:948) @ java.text.dateformat.format(dateformat.java:336) @ org.freixas.jcalendar.jcalendarcombo.paramstring(jcalendarcombo.java:780) @ java.awt.component.tostring(component.java:8095) tbmodel = (defaulttablemodel)tblitmqty.getmodel(); system.out.println(calrecvdate.getdate()); try{ if(calrecvdate.getdate()==null){ // error joptionpane.showmessagedialog(null, "please select shippment received date"); calrecvdate.requestfocus(); }else if(txtshipss.gettext().isempty()){ ////////////////////////////////////////////////////////////////
if (inputvalidate() == true) { try { string shipid = txtshipid.gettext(); string invid = txtinvoice.gettext(); string shipss = txtshipss.gettext(); string address = txtntfaddress.gettext(); string sipper = txtashipper.gettext(); string vessal = txtvessal.gettext(); date rcvdate = calrecvdate.getdate(); // jcalander string consignee = txtconsigne.gettext(); arraylist<shippmentitems> shipitems = new arraylist<shippmentitems>(); tbmodel = (defaulttablemodel) tblitmqty.getmodel(); (int = 0; < tbmodel.getrowcount(); i++) { string itmcode = (string) tbmodel.getvalueat(i, 0); string itmname = (string) tbmodel.getvalueat(i, 1); int qty = (int) tbmodel.getvalueat(i, 2); shippmentitems shpitems = new shippmentitems(shipid, itmcode, itmname, qty); shipitems.add(shpitems); }
since throws npe:
calrecvdate.getdate()==null the calrecvdate variable null, , either need check if it's null before using it, or make sure isn't null tracing in code think you've initialized , fix problem (since isn't initialized).
to check if it's null, do:
if (calrecvdate != null) { // use calrecvdate variable here } else { // initialize calrecvdate variable here // or perhaps better, display joptionpane error message user // date hasn't been selected, , exit method calling return: return; } again, don't use try/catch blocks handle nullpointerexceptions.
Comments
Post a Comment