问题描述
packageinternal.cus;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.util.ArrayList;importjava.util.Iterator;importjava.util.List;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;importcom.lzw.dao.Dao;importcom.lzw.item.Item;importcom.lzw.model.TbCusinfo;publicclassCustModiextendsJFrame{privateJComboBoxcus_no;privateJComboBoxname;privateJTextFieldsnm;privateJTextFieldpost;privateJTextFieldtel;privateJTextFieldfax;privateJTextFieldtelpople;privateJTextFieldemail;privateJTextFieldaddress;privateJTextFieldbank;privateJTextFieldbankno;privateJButtonbuttonadd;privateJButtonbuttonesit;publicCustModi(){super();setTitle("客户信息修改与删除");setLayout(null);setBounds(190,160,650,300);finalJLabellabel_1=newJLabel("客户编号:");label_1.setBounds(15,10,100,18);getContentPane().add(label_1);cus_no=newJComboBox();initComboBox();//初始化客户下拉框cus_no.setBounds(100,10,100,18);getContentPane().add(cus_no);finalJLabellabel_2=newJLabel("客户全称:");label_2.setBounds(220,10,100,18);getContentPane().add(label_2);name=newJComboBox();name.setBounds(300,10,300,18);getContentPane().add(name);finalJLabellabel_3=newJLabel("客户简称:");label_3.setBounds(15,40,100,18);getContentPane().add(label_3);snm=newJTextField();snm.setBounds(100,40,200,18);getContentPane().add(snm);finalJLabellabel_4=newJLabel("邮政编码:");label_4.setBounds(315,40,100,18);getContentPane().add(label_4);post=newJTextField();post.setBounds(395,40,205,18);getContentPane().add(post);finalJLabellabel_5=newJLabel("电话:");label_5.setBounds(15,70,100,18);getContentPane().add(label_5);tel=newJTextField();tel.setBounds(100,70,200,18);getContentPane().add(tel);finalJLabellabel_6=newJLabel("传真:");label_6.setBounds(315,70,100,18);getContentPane().add(label_6);fax=newJTextField();fax.setBounds(395,70,205,18);getContentPane().add(fax);finalJLabellabel_7=newJLabel("联系人:");label_7.setBounds(15,100,100,18);getContentPane().add(label_7);telpople=newJTextField();telpople.setBounds(100,100,200,18);getContentPane().add(telpople);finalJLabellabel_8=newJLabel("电邮:");label_8.setBounds(315,100,100,18);getContentPane().add(label_8);email=newJTextField();email.setBounds(395,100,205,18);getContentPane().add(email);finalJLabellabel_9=newJLabel("地址:");label_9.setBounds(15,130,100,18);getContentPane().add(label_9);address=newJTextField();address.setBounds(100,130,500,18);getContentPane().add(address);finalJLabellabel_10=newJLabel("开户银行:");label_10.setBounds(15,160,100,18);getContentPane().add(label_10);bank=newJTextField();bank.setBounds(100,160,200,18);getContentPane().add(bank);finalJLabellabel_11=newJLabel("银行账号:");label_11.setBounds(315,160,100,18);getContentPane().add(label_11);bankno=newJTextField();bankno.setBounds(395,160,205,18);getContentPane().add(bankno);buttonadd=newJButton("删除");//buttonadd.addActionListener(newbuttonaddActionListener());buttonadd.setBounds(200,220,100,22);getContentPane().add(buttonadd);buttonesit=newJButton("修改");buttonesit.setBounds(300,220,100,22);getContentPane().add(buttonesit);}//初始化客户代号下拉框publicvoidinitComboBox(){Listtbcusinfo=Dao.getCust();List<TbCusinfo>items=newArrayList<TbCusinfo>();cus_no.removeAllItems();for(Iteratoriter=tbcusinfo.iterator();iter.hasNext();){Listelement=(List)iter.next();TbCusinfotbc=newTbCusinfo();tbc.setCus_no(element.get(0).toString().trim());if(items.contains(tbc))continue;items.add(tbc);cus_no.addItem(tbc);}}//启动窗体信息publicstaticvoidlaunch(){java.awt.EventQueue.invokeLater(newRunnable(){publicvoidrun(){newCustModi().setVisible(true);}});}}初始化客户代号下拉框时,会报以下错误,提示在红色部分。Exceptioninthread"AWT-EventQueue-0"java.lang.ClassCastException:net.sourceforge.jtds.jdbc.JtdsResultSetcannotbecasttojava.util.Listatinternal.cus.CustModi.initComboBox(CustModi.java:139)atinternal.cus.CustModi.<init>(CustModi.java:49)atinternal.cus.CustModi$1.run(CustModi.java:155)atjava.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)atjava.awt.EventQueue.dispatchEvent(EventQueue.java:597)atjava.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)atjava.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)atjava.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)atjava.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)atjava.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)atjava.awt.EventDispatchThread.run(EventDispatchThread.java:122)
解决方案
解决方案二:
类型转换异常?你那两个东西能强转么?Dao.getCust();返回是个什么样的?
解决方案三:
Listelement=(List)iter.next();TbCusinfotbc=newTbCusinfo();应该是TbCusinfotbc=(TbCusinfo)iter.next();吧