I\'m getting a really annoying error, saying I\'m getting a null pointer exception but there\'s an if statement to check to see if the text is null before proceeding:
<My guess is either textToAdd
or RF
is null.
If textToAdd
is a JTextComponent (or subclass, but I'm guessing here), then its getText() method CANNOT return null. Therefore, Text
CANNOT be null, as this test shows.
package test;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class TextComponentTest extends JFrame {
JTextField tf;
public TextComponentTest() {
super();
tf = new JTextField();
getContentPane().add(tf);
}
public static void main(String[] args) {
TextComponentTest test = new TextComponentTest();
test.setVisible(true);
String s = test.tf.getText();
System.out.println(">" + s + "<");
System.out.println(">" + s.length() + "<");
test.tf.setText(null);
s = test.tf.getText();
System.out.println(">" + s + "<");
System.out.println(">" + s.length() + "<");
}
}
Output is:
><
>0<
><
>0<
if(Text.equals(null));
The above will throw a NullPointerException each time Text is null. Anytime you use the "." operator on null you get a NullPointerException.
If you are getting a NPE after if(Text != null), please post the stack trace.