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) Meet Objects Creating New Objects

Sebastiaan van Vugt
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sebastiaan van Vugt
Python Development Techdegree Graduate 13,554 Points

constructor GoKart in class GoKart cannot be applied to given types

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart kart = new GoKart();
System.out.printf("The GoKart color is %s\n",
                  kart.getColor());
    }
}

gives the following error:

error.java
./Example.java:5: error: constructor GoKart in class GoKart cannot be applied to given types;
      GoKart kart = new GoKart();
                    ^
  required: String
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error

Any idea what's wrong?

Ken Alger
Ken Alger
Treehouse Teacher

Edited for code markdown

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Sebastiaan;

Welcome to Treehouse!

You are missing something in your kart creation line. If you recall from the course, and from the Task 1 instructions, when we create a new kart with new GoKart(), we need to input a parameter of type String. Conceptually this would be the color of the GoKart we are creating. So we could do something like:

GoKart blueKart = new GoKart("blue");

Since you left out a color parameter in your item creation, it will give the above error.

Post back if you are still stuck.

Happy coding,
Ken