Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I valid my invalid cast?

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I have an error which says I used invalid cast from int to boolean! but the other side strWork is string and I do not understand what it says?
Could you please help me on this?
Many thanks,
Elahe
Error:
=========
Invalid cast from int to boolean.
if( strWork.compareTo( "0" ) ) {
^
Invalid cast from int to boolean.
else if( strWork.compareTo( "1" ) ) {
^
2 errors

If you like to see whole file:


[/code]
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compareTo() method of the String class returns an int. An "if" test requires a boolean. Why not use the equals() method instead. It returns a boolean and should solve your problem.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Marilyn and now it works
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic