This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't find out the error

 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is on line no 97 but i don't know what .
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you might be missing some brackets around the block following line 96. Have another look there.
 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot man . Solved the error .
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're comparing Strings (e.getPropertyName() and JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) using == while you should be using the equals method.
 
budsy remo
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ==?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic