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 trialFarouk Charkas
1,957 PointsI also need help on this task!
So I have written the code below the question and I have been getting this error:
'''
./GoKart.java:7: error: ';' expected
String getColor() {
^
./GoKart.java:8: error: incompatible types: unexpected return value
return color;
^
2 errors '''
Sorry if that was unclear but this is it: ./GoKart.java:7: error: ';' expected String getColor() { ^ ./GoKart.java:8: error: incompatible types: unexpected return value return color; ^ 2 errors
and I would like to know how to fix this! Thanks in advance!
public class GoKart {
private String mColor;
public GoKart (String color) {
mColor = color;
String getColor() {
return color;
}
}
}
Farouk Charkas
1,957 PointsYep that was the problem, thank you for coping with my bugging demands!
2 Answers
Jon Kussmann
Courses Plus Student 7,254 Pointspublic class GoKart {
private String mColor;
public GoKart (String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
Farouk Charkas
1,957 PointsYes, it took out some errors, so I added "String" between public and GoKart, that seemed to take off 1 of 2 errors, it then said "no return statement"
Jon Kussmann
Courses Plus Student 7,254 PointsI wasn't very careful. I'll update the above answer
You should return "mColor" instead of "color" in your getColor() method.
Farouk Charkas
1,957 PointsThat did not help since the default workspace adds it for me, it still has the "No return statement"
Farouk Charkas
1,957 PointsThat did not help since the default workspace adds it for me, it still has the "No return statement"
Farouk Charkas
1,957 PointsThat did not help since the default workspace adds it for me, it still has the "No return statement"
Jon Kussmann
Courses Plus Student 7,254 Pointspublic class GoKart {
private String mColor = "red";
public GoKart(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
I was able to complete the task with that.
Farouk Charkas
1,957 PointsOh maybe because I put string between public and GoKart
Farouk Charkas
1,957 PointsOh maybe because I put string between public and GoKart
Jon Kussmann
Courses Plus Student 7,254 PointsHi Evering,
It looks like you have an extra "}". Try deleting the second to last one.
I hope that helps. If not please let me know.
Farouk Charkas
1,957 PointsI appreciate your suggestion Mr. Kussman,
But no that does not work since I opened three code blocks but you suggested I end only two, that did not work for me.
Jon Kussmann
Courses Plus Student 7,254 PointsYou also have to add one right before you declare the getColor method. I'll paste what it should look like.
Farouk Charkas
1,957 PointsFarouk Charkas
1,957 PointsYep that was the problem, thank you for coping with my bugging demands!