Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Why doesn't this code work?

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'm stumped. This is probably a really stupid error, but I can't figure out why this code isn't working. This may be due to the fact that I'm on antihistamines right now and am feeling a little loopy.
This doesn't work:

Neither does

Method getIcon() looks like this:

In both cases, the println check before the "if" statement correctly prints out null (so getIcon() is indeed returning null), but for some reason the "if" statement isn't catching it. Why not? To my medicated brain it seems like this should work perfectly. Any ideas why it isn't?

[This message has been edited by Matt Senecal (edited May 10, 2001).]
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I tryed a similar example and it works ! I put Integer instead of
ImageIcon to be more simple. Have a look:
public class TestData {
private Integer theIcon = null;
public Integer getIcon() {
return theIcon;
}
public static void main(String [] a){

TestData tempData = new TestData();
System.out.println("ICON: "+tempData.getIcon());
if (tempData.getIcon()==null){
System.out.println("Am I even getting here?");
}
}
}
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still have no idea why this doesn't work. I ended up working around it. I initialized the ImageIcon to new ImageIcon() instead of null, and did the check this way:
if (tempData.getIcon().getImage() == null)
That worked.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic