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 trialOliver Acevedo
4,338 PointsMissing 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
26,676 PointsHi 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;
}
Oliver Acevedo
4,338 PointsThank you! So if I was declaring it as a method before, what are you declaring it as?
Chris Shaw
26,676 PointsMethods 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
4,338 PointsOh 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
26,676 PointsCorrect, 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
Mark Josephsen
8,803 PointsMark Josephsen
8,803 PointsAgreed. 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.