0
請幫我弄清楚這裏出了什麼問題?剛開始用java。組件未初始化投擲NUllPointerException
public class PropertyChangeListenerTest {
private JPanel mainPanel = null;
private JTextField source = null;
private JTextField target = null;
PropertyChangeListenerTest() {
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(1, 0, 10, 0));
source = new JTextField(20);
target = new JTextField(20);
mainPanel.add(source);
mainPanel.add(target);
}
JPanel getMainPanel() {
return mainPanel;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
protected static void createAndShowGUI() {
JFrame f = new JFrame("PropertyChangeListener");
f.getContentPane().add(new PropertyChangeListenerTest().getMainPanel());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
}
有沒有'NullPointerException'當我運行此代碼,您可以加入堆棧跟蹤和更多的解釋什麼是壞到您的文章。 。? – Sorceror
將來添加更多標籤。 –
它適合我!我從Eclipse和命令行啓動它: –