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

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,676 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,676 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,676 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