当我尝试从数据库中检索数据时,我收到 NullpointerException 。我在for循环中得到了异常。我认为这是一个 EventDispatchHandler 问题,但我无法解决。请有人帮帮我吗?
public class Dao {
private static final SessionFactory sessionFactory = NewHibernateUtil.getSessionFactory();
public List<OrderEntry> findAll(){
try{
sessionFactory.getCurrentSession().beginTransaction();
return sessionFactory.getCurrentSession().createCriteria(OrderEntry.class).list();
}catch(Exception e){
return null;
}
}
的JFrame
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
loadData();
}
private void loadData() {
DefaultTableModel dtm = new DefaultTableModel();
dtm.addColumn("Cause");
dtm.addColumn("Lasttname");
dtm.addColumn("Firstname");
for(OrderEntry oe : this.dao.findAll()){
dtm.addRow(new Object[] {oe.getCause(), oe.getLastname(), oe.getFirstname()});
}
jTable1.setModel(dtm);
}
public class OrderEntry implements java.io.Serializable {
private Integer orderid;
private String reference;
private String type;
private String cause;
private String firstname;
private String lastname;
private String profession;
private Set investigationMaterials = new HashSet(0);
public OrderEntry() {
}
public OrderEntry(String reference, String type, String cause, String firstname, String lastname, String profession, Set investigationMaterials) {
this.reference = reference;
this.type = type;
this.cause = cause;
this.firstname = firstname;
this.lastname = lastname;
this.profession = profession;
this.investigationMaterials = investigationMaterials;
}
public Integer getOrderid() {
return this.orderid;
}
public void setOrderid(Integer orderid) {
this.orderid = orderid;
}
public String getReference() {
return this.reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
}
public String getCause() {
return this.cause;
}
public void setCause(String cause) {
this.cause = cause;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return this.lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getProfession() {
return this.profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public Set getInvestigationMaterials() {
return this.investigationMaterials;
}
public void setInvestigationMaterials(Set investigationMaterials) {
this.investigationMaterials = investigationMaterials;
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at forensikmysql.UI.JInternalFrameShow.loadData(JInternalFrameShow.java:98)
at forensikmysql.UI.JInternalFrameShow.jButton1ActionPerformed(JInternalFrameShow.java:89)
at forensikmysql.UI.JInternalFrameShow.access$000(JInternalFrameShow.java:17)
at forensikmysql.UI.JInternalFrameShow$1.actionPerformed(JInternalFrameShow.java:59)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6527)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6292)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4883)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
org.hibernate.HibernateException:没有配置CurrentSessionContext! 在org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1011) 在forensikmysql.Util.Dao.findAll(Dao.java:22) 在forensikmysql.UI.JInternalFrameShow.loadData(JInternalFrameShow.java:98) 在forensikmysql.UI.JInternalFrameShow.jButton1ActionPerformed(JInternalFrameShow.java:89) 在forensikmysql.UI.JInternalFrameShow.access $ 000(JInternalFrameShow.java:17) 在forensikmysql.UI.JInternalFrameShow $ 1.actionPerformed(JInternalFrameShow.java:59) 在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2346) 在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6527) 在javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6292) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4883) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4705) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2739) at java.awt.Component.dispatchEvent(Component.java:4705) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746) at java.awt.EventQueue.access $ 400(EventQueue.java:97) at java.awt.EventQueue $ 3.run(EventQueue.java:697) at java.awt.EventQueue $ 3.run(EventQueue.java:691) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue $ 4.run(EventQueue.java:719) at java.awt.EventQueue $ 4.run(EventQueue.java:717) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:716) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)