0

Problem with getImage

asked 2010-01-05 07:22:10 +0800

andij62 gravatar image andij62
315 1 7

Hallo all,

if i check a Button whether it has an image with follow code

if (bt.getImage().equals("/img/xxx.png"))
...

and the Button has no Image set then occurs an error "NullPointerException".

Any idea whats wrong?

Best Regards

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2010-01-05 09:35:47 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

Simple trick:

"/img/xxx.png".equals(bt.getImage())

Explanation: if getImage() delivers null (as no image is attached with the button), there's no #equals() defined on null (nor any other method). Turning the order around your comparing your string to (maybe) null, which is false.

HTH, Maik

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-01-05 07:22:10 +0800

Seen: 294 times

Last updated: Jan 05 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More