【发布时间】:2009-07-05 21:43:46
【问题描述】:
我是 Java 新手,遇到这样的问题; 我有一个桌面应用程序,JFrame 中有 2 个 jComboBox。其中一个 jComboBox 是从 Personel Table 中保存 Personels,另一个是 Personel 的标题。当 jComboBox1 的选定索引发生更改时,它将获得 personelid 并用它的标题填充 jComboBox2。就是这样simple.But when selected index changes it filling with titles but showing something like Ljava.lang.object.xxxxx...
ERROR http://img243.yukle.tc/images/7070error.jpg
这是我的代码;
if (jComboBox1.getSelectedItem() !=null) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SwingDenemePU");
EntityManager em = emf.createEntityManager();
Query sorgu = em.createQuery("from Personel p,Unvan u where p.unvanID = u.unvanID and u.unvanID=:id");
int id = ((Unvan)jComboBox1.getSelectedItem()).getUnvanID();
sorgu.setParameter("id", id);
personelList = sorgu.getResultList();
Object[] items = new Object[personelList.size()];
for (int i = 0; i < personelList.size(); i++) {
items[i] = personelList.get(i);
}
DefaultComboBoxModel def = new DefaultComboBoxModel(items);
jComboBox2.setModel(def);
如果我将 items[i] = personelList.get(i) 更改为 ;
Personel personel = personelList.get(i);
items[i]=personel.getPersonelAdSoyad();
我在线程“AWT-EventQueue-0”中遇到异常 java.lang.ClassCastException: [Ljava.lang.Object;无法转换为 DBClasses.Personel 错误。
【问题讨论】:
标签: java hibernate swing jpa jcombobox