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 (Retired) Creating the MVP Strings and Chars

constructor in a scrabble game

Error Alert! Constructor in Scrabble player in class scrabble player cannot be applied to given types? new ScrabblePlayer

ScrabblePlayer.java
public class ScrabblePlayer {
    private String mHand;

    public  ScrabblePlayer(String hand) {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }
    public void addTile(char tile) {
      mHand += tile;
        // Adds the tile to the hand of the player
    }

    public boolean hasTile(char tile) {
       return mHand.indexOf(tile) >-1;
    }
  public int getTileCount(char tile){
    int counter = 0;
    for(char letter: mHand.toCharArray()){
      if(letter == tile){
        counter += 1;
}
    }
    return counter;
  }
}

2 Answers

Hmm if your problem is with the challenge, you don't need the getTileCount method. Remove it and try again. I copied these two lines of code into my challenge and it worked just fine:

mHand += tile;

and

return mHand.indexOf(tile) >-1;

I noticed that your constructor doesn't actually initialize the mHand variable? This would throw some of the other methods off as they try to iterate through an empty String. Try:

public  ScrabblePlayer(String hand) {
        mHand = hand;
    }

Hopefully that helps :)