Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Improving Our Code Creating a Class

Oliver Acevedo
Oliver Acevedo
4,338 Points

Missing return statement?

Code challenge asks me to, "Now add a String member variable named mTitle. Make it public." but I get a compile error stating that " missing return statement"?

I thought you could only write a return statement once a variable has been declared?

Here's my code:

public class PictureBook {
  public String mTitle() {

  }
}

3 Answers

Chris Shaw
Chris Shaw
26,650 Points

Hi Oliver,

You're declaring your mTitle variable as a method which requires a return statement if it's not of the type void, what you should have is the below.

public class PictureBook {
  public String mTitle;
}
Mark Josephsen
Mark Josephsen
8,803 Points

Agreed. Methods that aren't declared as 'void' must have a return statement. Since you've declared mTitle as a method, you're getting a compile error.

Oliver Acevedo
Oliver Acevedo
4,338 Points

Thank you! So if I was declaring it as a method before, what are you declaring it as?

Chris Shaw
Chris Shaw
26,650 Points

Methods are declared using parentheses which is what you posted, variables or properties as they're better known are declared with either a value that matches the type or nothing at all like I posted above.

Oliver Acevedo
Oliver Acevedo
4,338 Points

Oh ok, I understand now. So I was supposed to declare mTitle simply as a variable but I declared it as a method. Thanks!

Chris Shaw
Chris Shaw
26,650 Points

Correct, I think something that might be beneficial for you is to watch some introduction videos just to get accustom to the differences.

http://teamtreehouse.com/library/introduction-to-programming