我为我的 CRUD 程序编写了一个 gui,当我想运行它时,我得到:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gui.guimain$1.run(guimain.java:477)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
这就是 NPE 来自的代码:
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run(){
maingui.showStart();// thats the line with the Exception
}
});
}
这就是 showStart() 方法:
public void showStart(){
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.getContentPane().removeAll();
tabstructure.removeAll();
Produkt filter=new Produkt();
JPanel P=new JPanel();
P=Produktgui(0, filter);
JPanel R=new JPanel();
R=Billgui(0);
JPanel nR=new JPanel();
nR=Billgui(0);
tabstructure.addTab("e", P);
tabstructure.addTab("Bills", R);
tabstructure.addTab("Pay bill", nR);
mainFrame.getContentPane().add(tabstructure);
mainFrame.validate();
mainFrame.repaint();
mainFrame.pack();
mainFrame.setVisible(true);
}
为什么我得到一个NullPointerException
?