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

Thomas James
Thomas James
5,580 Points

constructor Game in class cannot be applied to given types

Hi all,

In Prompting for guesses video I keep getting the following error:

treehouse:~/workspace$ javac Hangman.java && java Hangman
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Hangman.java:5: error: constructor Game in class Game cannot be applied to given types;
Game game = new Game("treehouse");
^
required: String,String,String
found: String
reason: actual and formal argument lists differ in length
1 error
treehouse:~/workspace$

I think I understand why I am getting this error. My game classes has a constructor with three parameters, however when I create a game object in my hangman class I am only giving it one parameter, this being the answer. How do I fix? Unless I am being silly I don't think the video differs to my code. Please help

1 Answer

I do not remember the video but if you have 3 parameters required for constructor, you have to provide 3 parameters when you create an object. You can change the constructor to accept 1 parameter. Show me your code if you want more specific answer.