pro_java thread: Re: Question on reading data from a textbox..
GINO,
I take it your using javax.swing.JTextField. The snippet of code you
have there should work. However, how are you finding your receiving NULL?
According to the Java documentation a NullPointerException will be thrown
if the "underlying document is null". Try to catch a NullPointerException
with something like this:
try
{
String text = txtTextBoxName.getText();
}
catch(NullPointerException e)
{
System.err.println("Ugh! A null pointer exception!");
}
Are you comparing String references instead of string values?
You should compare strings like
// Check lexicographically where text follows "Another string"
String str = "Another string";
if(text.compareTo(str) > 0)
// Do something...
NOT:
// Compare two string references to see if they reference the same object
// in memory.
String str = "Another string";
if(text == str)
// Do something...
-Aaron
> This is my code that I'm using
>
> String text = txtTextBoxName.getText();
>
> When I run it and enter something in the textbox. Its always NULL.
> It does get the value...
> GINO