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 Counting Scrabble Tiles

I don't know what i am missing in the for loop.

the error that appears: ./ScrabblePlayer.java:22: error: bad initializer for for-loop for(letter : tiles.toCharArray()){ ^ the code i wrote: public int getCountOfLetter (char letter) { for(letter : tiles.toCharArray()){ int count = 0;

  if(tiles.indexOf(letter) != -1){
  return count;



1 Answer


error: bad initializer for for-loop

This error is there because you have not initialized the first parameter of the for loop.

//Just like we initialize an int in the example of 
for(int i; i < 10; i++)

// We need to do the same for an enhanced for loop
for (int myValue : myArray)


Add the initialization to your value

 for( char l : tiles.toCharArray())

Good luck on the rest of the task, i would suggest remove your current if statement and think how you can compare your value you initialized to the letter of the getCountOfLetter char parameter.


if (value == parameter){

Thanks a lot for helping, it worked out just fine :)