freelanceprogrammers.org Forum Index » Java

empty textfield value


View user's profile Post To page top
ooomadhatterooo Posted: Sun Feb 10, 2002 6:41 pm


Joined: 31 Jan 2002

Posts: 26
empty textfield value
What is the value returned by surname.getText()
of a textfield, if someone doesn`t enter any value?
How do you test for it?<br><br>I tried:<br>if
(surname.getText() == "")<br>and<br>if (surname.getText() ==
null)<br>but neither seems to work - or am I doing something
else wrong?<br><br>Thanks.
Reply with quote
Send private message
View user's profile Post To page top
gblue42 Posted: Sun Feb 10, 2002 10:18 pm


Joined: 10 Feb 2002

Posts: 15
empty textfield value
Try using the equals() method like so:<br><br>if
(surname.getText().trim().equals(""))
Reply with quote
Send private message
View user's profile Post To page top
epenak Posted: Mon Feb 11, 2002 10:46 pm


Joined: 31 Jan 2002

Posts: 39
empty textfield value
If surname has not been initialized it will be
null. You will experience a NullPointerException
whenever you try to call one of surname`s methods in this
situation. <br><br>Test first for the null.<br>if (surname
!= null) {// do work here}<br><br>My 2
cents<br>epenak
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help