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 trialLeen Leenaerts
1,096 PointsI'm getting the error : ./GoKart.java:4: error: invalid method declaration; return type required...
./GoKart.java:4: error: invalid method declaration; return type required public setColor(String color) { ^ 1 error
I don't see why I need to return something to set the Color of the Gokart.
public class GoKart {
private String mColor = "red";
public setColor(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
2 Answers
Luke Glazebrook
13,564 PointsHello Leen!
If you don't think you need to return anything then put the keyword 'void' where you would usually put what the function is going to return.
Void is a special keyword in Java which signifies that the function isn't going to return anything.
I hope this helped you out and good luck with your programming!
-Luke
Leen Leenaerts
1,096 PointsIt was supposed to be a constructor so I just needed to put the keyword "GoKart". Thanks for learning me "void".
Luke Glazebrook
13,564 PointsNo problem! I am glad you managed to get your problem solved.