Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Creating the MVP Scrabble Tiles

I keep getting an error of cannot find symbol when trying to do boolean isTile = addTile.indexOf(tile);

Question: Correct the existing hasTile method to return true if the tile is in the tiles field, and false if it isn't. You can solve this a few ways, however, I'd like you to practice returning the result of the expression that uses the index of a char in a String.

Error msg: ./ScrabblePlayer.java:20: error: cannot find symbol boolean isTile = addTile.indexOf(tile); ^ symbol: variable addTile location: class ScrabblePlayer

2 Answers

AddTiles is a method with no return value. The variable this.tiles is the String representing all of the tiles that this player has. Try that with indexOf.

Andy Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy Stevens
Front End Web Development Techdegree Graduate 20,417 Points

indexOf will return -1 if the value is not found in the String as such your code should evaluate whether the String is greater than or equal to 0 i.e. is a char found.

I would write something like

return tiles.indexOf(tile) >= 0;

Let me know if this answers your question.