jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Error Message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error Message" Watch "Error Message" New topic
Author

Error Message

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I'm trying to put an error message out to a panel but my statement isn't working and it is just like my example. Do you have any suggestions?
if (Shares.getText().equals(null))
{
System.out.println("I get here.");
ErrorMsg.setText("Shares is missing.");
System.out.println(ErrorMsg.getText());
}
The first line prints that message but I don't get anything on the panel or last line. ErrorMsg is a label.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi candy,
we have to get the text value from the textfield and compare it like,
textfield.getText().equals("")
not with null as you are doing...
try this and see if it works..
regards
maulin
Gary McGath
Ranch Hand

Joined: Mar 15, 2003
Posts: 52
If I understand you correctly, your log or console is printing out "I get here.", but nothing further after that. This suggests that the comparison to null is working (though using an == comparison would be a tiny bit more efficient), but the setText call is throwing an exception. I'd put a try{} around the whole thing, followed by
catch (Exception e) {
e.printStackTrace();
}


http://www.mcgath.com/consulting/
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
And if you are getting an exception on ErrorMsg.setText, it is most likely a NullPointerException. Is ErrorMsg already initialized and added to the GUI?
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I'm not getting an exception. I just not getting anything.
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
Hey, changing the if statement to
textfield.getText().equals("")
fixed the problem. I didn't think it would because the statement seemed to be working as it was but now it works as it should. Thank you so much.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
So when you said "The first line prints that message", what were you talking about? Is it possible that there's some other part of the program that also prints "I get here" and you were confused by this?


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Message