javax.swing.JComboBox无法强制转换为javax.swing.ComboBoxModel

时间:2015-02-28 21:09:03

标签: java pointers combobox null jcombobox

我在java中使用ComboBox。当我将ComboBox的项目发送到另一个类时。

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JComboBox cannot be cast to javax.swing.ComboBoxModel at ekspeditorv3.Odenish.jComboBox1ActionPerformed(Odenish.java:144) at ekspeditorv3.Odenish.access$300(Odenish.java:16) at ekspeditorv3.Odenish$4.actionPerformed(Odenish.java:74) at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1258) at javax.swing.JComboBox.contentsChanged(JComboBox.java:1331) at javax.swing.JComboBox.intervalRemoved(JComboBox.java:1351)

这是我的代码:

private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
   Qosulma.BorcuGoster(jComboBox1.getSelectedItem().toString(), BorcLabel);
 }

这是我的qosulma课程:

static void BorcuGoster(String toString, JLabel jLabel3) {
        try {
            Statement statYoxla = con.createStatement();
            String Query2 = "SELECT * FROM orders WHERE  CUSTOMERNAME='" + toString + "'";
            ResultSet rsYoxla = statYoxla.executeQuery(Query2);
            double say = 0;
            while (rsYoxla.next()) {
                say = say + rsYoxla.getDouble(6);
            }
            jLabel3.setText(String.valueOf(say));
        } catch (SQLException ex) {
            Logger.getLogger(Qosulma.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

1 个答案:

答案 0 :(得分:0)

此方法发生异常(由不兼容的类型转换引起):jComboBox1ActionPerformed。如果它是您编写的方法,请检查您在那里做了什么。如果它是您未编写的库中的方法,请阅读其文档并确保按照您的意愿使用它。