aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 9043
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I valid my invalid cast?
 
Similar Threads
Question on cache control...
How can I solve this problem?
How can I show part of my text in my template?
Need help! Request Headers!
Can not solve my problem....