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

error: missing return statement

My Error message is error: missing return statement

And the code it is for is

public String goKart {


public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");

  public String goKart(){


2 Answers

Hello Sean!

I'm not sure what you have to do in this task but In your second method you are saying to the compiler that you are returning a String, so you should return something for example:

 public String goKart(){

 return stringVariable;

Check this link out it might help you!


Brody Ricketts
Brody Ricketts
15,612 Points

Sean Gwall

You are trying to create what looks like a method. You declared that the return type of the method is a string, so when you don't use the return keyword in your block of code, you will get that compiler error as you did.

What the task is asking you to do is create a new object.

Have a look at Creating Classes. You will find your answer in this video.

Lastly a few tips on asking questions on the forums:

  1. Try wording your question with what the actual problem is, for instance on this question, "How do I create a new object?", rather than "error: missing return statement."
  2. Add as much information to your question as possible.
  3. If you're stuck, try searching for your specific task using your favorite search tool, mine is google. 9/10 times this will populate your search will previously asked questions here on the forums.