NeoChaosX
October 27th, 2005, 12:30 AM
Okay, I need some help here. I need to add a listener to a JTextField that gets the data that's in the JTF. However, everytime I run the program, I keep getting NullPointerExceptions when the Listener runs. Here's my code for adding the listener -
JTextField tf = new JTextField("" + d.getValueAt(i), 20);
final JTextField f = tf;
tf.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int value = Integer.getInteger(f.getText());
// remaining code here
. . .
}
});
From the readouts on the code, it's messing up where it's doing the getText() method. So, am I doing this right? Or is there another way to add a Listener that will check for changes in the TextField without blowing up with NullPointerExceptions?
JTextField tf = new JTextField("" + d.getValueAt(i), 20);
final JTextField f = tf;
tf.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int value = Integer.getInteger(f.getText());
// remaining code here
. . .
}
});
From the readouts on the code, it's messing up where it's doing the getText() method. So, am I doing this right? Or is there another way to add a Listener that will check for changes in the TextField without blowing up with NullPointerExceptions?