0
S'il vous plaît aidez-moi à comprendre ce qui ne va pas ici? juste débutant en Java.Composants non initialisés lancer 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);
}
}
Il n'y a pas 'NullPointerException' quand je lance ce code, pourriez-vous ajouter stacktrace et plus d'explications ce qui est mauvais à votre poste. ? – Sorceror
Ajouter plus de tags dans le futur. –
Ca marche pour moi! Je l'ai démarré depuis Eclipse et en ligne de commande: –