• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is trim not working?

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks ,
Im trying to trim a field(remove all whitespaces , in the following manner)

but i get the following exception.

Any idea why im getting the exception?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Switch (stractualflow != "") to !stractualflow.equals(""), and see if that helps. Remember you should never use == and != to compare Strings.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why are you using floats?
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With this code you can drop the check for stractualflow != null, because if it were null the trimming would have already thrown a NullPointerException.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also put spaces between tokens. It is much easier to read if (sfractualValue != null) ... than if(sfractualValue!=null) ...
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And also put spaces between tokens. It is much easier to read if (sfractualValue != null) ... than if(sfractualValue!=null) ...


And it is MUCH easier to read it the positive way...

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys !
 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic