-3

我正在尝试从 jComboBox1 更新其他 Jcomboboxes(With ItemStateChanged Event)。我发现很难知道为什么下面的代码会抛出 Null Pointer Exception 。(jComboBox5 已通过 jComboBox1 更新)当我尝试从 jComboBox1 中选择一个元素时,我得到 NPE 。

  private void jComboBox3ItemStateChanged(java.awt.event.ItemEvent evt) {                                            
        // TODO add your handling code here:
        try {
            System.out.println("Count" + jComboBox3.getItemCount());
            if(jComboBox3==null)
            {
                System.out.println("xczxzvzvvxzxzxc999");
            }
            if (jComboBox3.getItemCount() > 1) {
                System.out.println("Selected 3 element"+jComboBox3.getSelectedItem());
     /*Line 1136*/           if (jComboBox3.getSelectedItem().toString().equals("New Payment Term") == true) {
                    jComboBox3.setSelectedIndex(0);
                    ims.MainWindow.jDesktopPane1.add(new ims.Payment.PaymentTerms("Cust"), javax.swing.JLayeredPane.DEFAULT_LAYER);
                }
            }
        } catch (Exception x) {
            x.printStackTrace();
        }
    }        

下面是堆栈跟踪

java.lang.NullPointerException
    at ims.Customer.CustomerFrame.jComboBox3ItemStateChanged(CustomerFrame.java:1136)
    at ims.Customer.CustomerFrame.access$100(CustomerFrame.java:22)
    at ims.Customer.CustomerFrame$2.itemStateChanged(CustomerFrame.java:387)
    at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1225)
    at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1273)
    at javax.swing.JComboBox.contentsChanged(JComboBox.java:1329)
4

1 回答 1

1

为了找到在java.lang.NullPointerException异常发生的行上放置断点的原因,在这种情况下为 1136,并调查该行上的变量。

我的猜测是jComboBox3.getSelectedItem()正在回归null

于 2013-02-11T17:32:02.670 回答