Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes How can I valid my invalid cast? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can I valid my invalid cast?" Watch "How can I valid my invalid cast?" New topic
Author

How can I valid my invalid cast?

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
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

Joined: Jul 22, 2000
Posts: 9044
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Many thanks Marilyn and now it works
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How can I valid my invalid cast?
 
Similar Threads
Can not solve my problem....
How can I show part of my text in my template?
Question on cache control...
Need help! Request Headers!
How can I solve this problem?