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
Lucas Santos
19,315 PointsPlease help do not understand why i'm getting this error and code isn't running. I followed the example.
my class:
//class
public class GoKart{
//fields
private String mGoKartColor;
//constructor
public GoKart(String color){
mGoKartColor = color;
}
//method
public String getGoKartColor(){
return mGoKartColor;
}
}
Then on my example.java
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a new go kart.");
//ClassName __ instance variable __ new __ ClassName__
GoKart kart = new GoKart("blue");
System.out.printf("The color of the new kart is %s ", kart.getGoKartColor());
}
}
and the error I keep on getting is:
location: class Example
Example.java:7: error: cannot find symbol
GoKart kart = new GoKart("blue");
^
symbol: class GoKart
location: class Example
2 errors
really do not understand why, I went over the examples DOEZENS of times and thought I understood this but I guess not.
I had to ask this again because im trying to follow along with the lesson and try out my code but doesn't seem to be working.
2 Answers
Craig Dennis
Treehouse TeacherAre these in two different files? What are their names? They need to match your class names.
boog690
8,987 PointsThe instructions read:
Print out using System.out.printf the color of the new object, using the getColor method.
Use the getColor() method, not getGoKartColor(). This exercise is using its OWN GoKart class and testing against that one. That GoKart class does not have a getGoKartColor() method.
Also, there's no need to repeat the class name in your member variables and methods. For instance, on a radio, it's not the "radio volume." It's just volume. The same thing applies for objects in Java.
I really hope this helped!
Lucas Santos
19,315 PointsIt's not a challenge it's just on the workspace so I think I can use my own class and experiment rite? Other than that I can't find an issue.
boog690
8,987 PointsApologies. I didn't realize it wasn't for the challenge. In that case, hmmm...
Lucas Santos
19,315 PointsNo worries really appreciate the help!
boog690
8,987 Pointsboog690
8,987 PointsThis is a good point. Is your Java file name == "GoKart.java"?
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsCraig you're the man! finally worked. The name of the file where I created the class was PezDispenser.java. I thought I could experiment on the same file... Good to know that the class name needs to be the same name as the file name.