Results 1 to 7 of 7
Thread: toString() method error?
- 02-06-2010, 11:10 PM #1
Member
- Join Date
- Nov 2009
- Location
- California
- Posts
- 55
- Rep Power
- 0
toString() method error?
Eclipse is telling me:
Multiple markers at this line
- Method breakpoint:Card [entry] -
toString()
- This method must return a result of
type String
- overrides java.lang.Object.toString
I don't understand why this is producing an error because my method returns a String. What is wrong?
Java Code://toString method public String toString(){ switch (card){ case 0: return "2 of Clubs"; case 1: return "3 of Clubs"; case 2: return "4 of Clubs"; case 3: return "5 of Clubs"; case 4: return "6 of Clubs"; case 5: return "7 of Clubs"; case 6: return "8 of Clubs"; case 7: return "9 of Clubs"; case 8: return "10 of Clubs"; case 9: return "Jack of Clubs"; case 10: return "Queen of Clubs"; case 11: return "King of Clubs"; case 12: return "Ace of Clubs"; case 13: return "2 of Spades"; case 14: return "3 of Spades"; case 15: return "4 of Spades"; case 16: return "5 of Spades"; case 17: return "6 of Spades"; case 18: return "7 of Spades"; case 19: return "8 of Spades"; case 20: return "9 of Spades"; case 21: return "10 of Spades"; case 22: return "Jack of Spades"; case 23: return "Queen of Spades"; case 24: return "King of Spades"; case 25: return "Ace of Spades"; case 26: return "2 of Hearts"; case 27: return "3 of Hearts"; case 28: return "4 of Hearts"; case 29: return "5 of Hearts"; case 30: return "6 of Hearts"; case 31: return "7 of Hearts"; case 32: return "8 of Hearts"; case 33: return "9 of Hearts"; case 34: return "10 of Hearts"; case 35: return "Jack of Hearts"; case 36: return "Queen of Hearts"; case 37: return "King of Hearts"; case 38: return "Ace of Hearts"; case 39: return "2 of Diamonds"; case 40: return "3 of Diamonds"; case 41: return "4 of Diamonds"; case 42: return "5 of Diamonds"; case 43: return "6 of Diamonds"; case 44: return "7 of Diamonds"; case 45: return "8 of Diamonds"; case 46: return "9 of Diamonds"; case 47: return "10 of Diamonds"; case 48: return "Jack of Diamonds"; case 49: return "Queen of Diamonds"; case 50: return "King of Diamonds"; case 51: return "Ace of Diamonds"; } }
- 02-06-2010, 11:23 PM #2
Member
- Join Date
- Nov 2009
- Location
- California
- Posts
- 55
- Rep Power
- 0
nevermind, I'm assuming the error is due to the fact that if it isn't within the range of 0-51 it doesn't return anything
- 02-07-2010, 12:27 AM #3
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
- 02-07-2010, 12:38 AM #4
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
I knew it!!! lolJust type retun null for example after the end brace of your switch statement.Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
- 02-07-2010, 12:51 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
The compiler won't complain, but perhaps the players might! I mean if you are playing Bridge and someone lays down the Joker (card==-1) that would generally be taken as something of a faux pas.
If the proper operation of the program depends on Card having a card value in a particular range, then throw an exception.
- 02-07-2010, 03:18 AM #6
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
- 02-07-2010, 03:19 AM #7
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
Similar Threads
-
Trying to write toString method
By curious in forum New To JavaReplies: 3Last Post: 10-28-2009, 02:43 AM -
toString() method
By 01allenh in forum New To JavaReplies: 2Last Post: 03-25-2009, 11:43 PM -
question about writing a toString method
By heather.diggs in forum New To JavaReplies: 2Last Post: 11-12-2008, 11:13 PM -
toString() method of java.security.MessageDigest
By Nicholas Jordan in forum Advanced JavaReplies: 4Last Post: 09-18-2008, 02:32 PM -
toString method
By apfroggy0408 in forum New To JavaReplies: 6Last Post: 01-31-2008, 04:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks