GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Can't find out the error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't find out the error

budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
Hi i'm getting a problem in my TheIcon Class . I am trying to implement a JFileChooser but when i want to use an accessory with it . I want to add an icon at a side which will display a thumbnail of the image being selected . The program works fine without the "TheIcon " class . I'll make the lines as bold where the error is showing . The error is : not a statement File f= (File) e.getNewValue();




budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
The error is on line no 97 but i don't know what .
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4397
    
    8

I think you might be missing some brackets around the block following line 96. Have another look there.
budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
@Matthew I have missed out a bracket in the post but not in code otherwise i would have had an "reached end of line while parsing" error .
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4397
    
    8

So what exactly do you think the scope of the variable you're declaring on line 97 is at the moment?
budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
i only need that variable for getting the name of the file so that i could get an icon and use setIcon() to the label . It's scope is within the propertyChange(PropertyChangeEvent e) .
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4397
    
    8

No it isn't. The scope is currently limited to that line only, because you've got an if statement (line 96) with no brackets following. Which means that only the following line is within the if block. You need to put brackets round the entire following block.
budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
Thanks a lot man . Solved the error .
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You're comparing Strings (e.getPropertyName() and JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) using == while you should be using the equals method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
shouldn't it work because the == checks for the same memory location and e.getPropertyName() would return a string at the same memory location as the JFileChooser's static string SELECTED_FILE_PROPERTY_CHANGED ???
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

It might, but are you sure it always will? What if the property name will be a new String similar to the constant but not the same in regards to ==?
 
GeeCON Prague 2014
 
subject: Can't find out the error