This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error Message" Watch "Error Message" New topic

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.");
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: 1873
hi candy,
we have to get the text value from the textfield and compare it like,
not with null as you are doing...
try this and see if it works..
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) {
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
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

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
It is sorta covered in the JavaRanch Style Guide.
subject: Error Message
jQuery in Action, 3rd edition