Mon application Java produit une exception de pointeur nul de JCalander Combobox. J'ai essayé d'attraper l'erreur. Mais cela n'a pas fonctionné. Quelqu'un peut-il m'aider à résoudre ce problème. S'il vous plaît.Exception de pointeur nul de JCalander Combobox
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1106)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:955)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:948)
at java.text.DateFormat.format(DateFormat.java:336)
at org.freixas.jcalendar.JCalendarCombo.paramString(JCalendarCombo.java:780)
at 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();
for (int i = 0; i < 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);
}
Où est le code? – Reimeus
Ne jamais attraper une exception NullPointerException mais plutôt trouver la ligne de code qui la provoque, trouver quelle variable sur cette ligne est nulle, puis remonter dans votre code pour voir pourquoi il n'a pas été initialisé. Si vous avez besoin de plus de notre aide, vous devrez nous en dire plus et nous montrer plus en nous montrant votre code pertinent, en nous disant quelle ligne est la ligne fautive, quelle variable est nulle, et où vous * pensez * vous êtes initialiser cette variable. –
@Reimeus Le code original a été mis à jour. – amal