-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
Asked: 2010-01-05 07:22:10 +0800
Seen: 294 times
Last updated: Jan 05 '10