我有一个问题,我创建了一个带菜单栏的swing应用程序,它在菜单中有三个项目但是当我点击一个菜单时它挂起系统无法进入另一个菜单..只有强制关闭才是最后一个选项。 / p>
下面是我的StackTrace ..任何人都可以知道哪里出错了?
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.openbravo.pos.perception.Per_panel.deactivate(Per_panel.java:211)
at com.openbravo.pos.forms.JPrincipalApp.showTask(JPrincipalApp.java:344)
at com.openbravo.pos.forms.MenuPanelAction.actionPerformed(MenuPanelAction.java:47)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at org.jdesktop.swingx.JXHyperlink.fireActionPerformed(JXHyperlink.java:266)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.openbravo.pos.perception.Per_panel.deactivate(Per_panel.java:211)
at com.openbravo.pos.forms.JPrincipalApp.showTask(JPrincipalApp.java:344)
at com.openbravo.pos.forms.MenuPanelAction.actionPerformed(MenuPanelAction.java:47)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at org.jdesktop.swingx.JXHyperlink.fireActionPerformed(JXHyperlink.java:266)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
错误代码
public Per_panel() throws ClassNotFoundException {
initComponents();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (com.mysql.jdbc.Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/unicentadb", "root", "ubuntu123");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select NAME from PRODUCTS");
while (rs.next()) {
parts.addItem(rs.getString("NAME"));
}
} catch (SQLException ex) {
}
}
@Override
public void init(AppView app) throws BeanFactoryException {
this.app = app;
// m_ticketsbag = getJTicketsBag();
// m_jPanelBag.add(m_ticketsbag.getBagComponent(), BorderLayout.LINE_START);
// add(m_ticketsbag.getNullComponent(), "null");
// m_ticketlines = new JTicketLines(dlSystem.getResourceAsXML("Ticket.Line"));
// m_jPanelCentral.add(m_ticketlines, java.awt.BorderLayout.CENTER);
// m_TTP = new TicketParser(m_App.getDeviceTicket(), dlSystem);
// Los botones configurables...
// m_jbtnconfig = new JPanelButtons("Ticket.Buttons", this);
// m_jButtonsExt.add(m_jbtnconfig);
//Panel products or lines ...
// catcontainer.add(getSouthComponent(), BorderLayout.CENTER);
// Tax model
// senttax = dlSales.getTaxList();
// senttaxcategories = dlSales.getTaxCategoriesList();
// taxcategoriesmodel = new ComboBoxValModel();
// ponemos a cero el estado
// stateToZero();
// inicializamos
// m_oTicket = null;
// m_oTicketExt = null;
}
@Override
public Object getBean() {
return this;
}
@Override
public String getTitle() {
return AppLocal.getIntString("Menu.panel");
}
@Override
public void activate() throws BasicException {
//paymentdialog = JPaymentSelectCustomer.getDialog(this);
//paymentdialog.init(app);
}
@Override
public boolean deactivate() {
return m_ticketsbag.deactivate();//To change body of generated methods, choose Tools | Templates.
}
@Override
public JComponent getComponent() {
return this;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
// int count = jTable1.getRowCount();
// int count1 = jTable1.getColumnCount();
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/unicentadb", "root", "ubuntu123");
// running varchar date String d1 = ((JTextField) jDateChooser1.getDateEditor().getUiComponent()).getText();
//System.out.println(d1);
//ResultSet rs = null;
// String dateValue = rs.getString(1,jDateChooser1); // What ever column
// String dateValue = jDateChooser1.getDateFormatString();
// java.util.Date jd = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").parse(dateValue);
String tf1 = perf.getText();
String tf2 = reason.getText();
String tf3 = fees.getText();
java.util.Date jd = date.getDate();
String tf5 = (String) parts.getSelectedItem();
// String tf9 = jTextField2.getText();
PreparedStatement pstmt = (PreparedStatement) con.prepareStatement("insert into MobileRep(pronumber,Reason,fees,delivery,parts) values(?,?,?,?,?)");
//running varchar date pstmt.setString(1, d1);
pstmt.setString(1, tf1);
pstmt.setString(2, tf2);
pstmt.setString(3, tf3);
pstmt.setDate(4, new java.sql.Date(jd.getTime()));
pstmt.setString(5, tf5);
// pstmt.setString(9,tf9);
pstmt.executeUpdate();
pstmt.close();
con.close();
} catch (Exception e)
{
System.out.println("Exception.." + e);
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
int i;
long value;
String output = "";
for (i = 1; i <= 1; i++) {
value = (new Date()).getTime();
//value = Math.random( );
output = output + "\t" + value + "\n";
perf.setText(output);
}
}
答案 0 :(得分:0)
@Override
public boolean deactivate() {
return true;
}
使用此方法问题将解决。