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 trialEnej Lah
Java Web Development Techdegree Student 957 PointsWhat is wrong here?
I have been making a challenge "Creating new objects". Which mistake have I done? Here is what console says:
./Example.java:5: error: cannot find symbol
mGoKartColor GoKart = new mGoKartColor ("red");
^
symbol: class mGoKartColor
location: class Example
./Example.java:5: error: cannot find symbol
mGoKartColor GoKart = new mGoKartColor ("red");
^
symbol: class mGoKartColor
location: class Example
2 errors
Here is what I wrote:
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
mGoKartColor GoKart = new mGoKartColor ("red");
System.out.printf("The GoKart color is %s.", GoKart.getColor);
}
}
4 Answers
jacobproffer
24,604 PointsYour error is telling you that mGoKartColor cannot be found. In other words, the class does not exist. As indicated in the challenge prompt, the class is called GoKart. In that case, you'd create a new instance of that class like so:
GoKart goKart = new GoKart("green"); // Pass in whatever color you prefer
Ken Alger
Treehouse TeacherEnej;
Isn't the object name we are trying to create GoKart
and not mGoKartColor
?
Post back if you are still stuck.
Ken
Enej Lah
Java Web Development Techdegree Student 957 PointsThank you! I tried that and now, I've complited the challenge.
Enej Lah
Java Web Development Techdegree Student 957 PointsThank you both for fixing that bug, but now there is one more error:
./Example.java:6: error: cannot find symbol
System.out.printf("The GoKart color is %s.", GoKart.getColor);
^
symbol: variable getColor
location: class GoKart
1 error
Currently, the program looks like:
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart goKart = new GoKart ("red");
System.out.printf("The GoKart color is %s.", GoKart.getColor);
}
}
jacobproffer
24,604 PointsHey Enej,
You access the getColor method like so:
System.out.printf(goKart.getColor());
In other words: objectName.methodName();
Using the string formatter, you can also do it this way:
System.out.printf("The color of the goKart is %s.", goKart.getColor());