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 trialvarghesejoseph
824 PointsHelp: Getting error - missing return statement
Hi guys
I get the error message below
./PictureBook.java:7: missing return statement } ^ 1 error
For a task to add a String member variable named mTitle. Make it public
and my code was
public class PictureBook {
public String mTitle () {
} }
3 Answers
Robert Komaromi
11,927 PointsIf the mTitle method is not going to return anything, you should write your code like so:
public class PictureBook
{
public void mTitle ()
{
// ...
}
}
Otherwise, the method should return a String, in which case, include a return statement which returns a string ...
public class PictureBook
{
public String mTitle ()
{
return "A string";
}
}
Molly Brower
1,915 PointsI'm having the same problem. I've tried...
public class PictureBook {
public String mTitle() {
}
}
...which throws the error:
./PictureBook.java:5: missing return statement
}
^
1 error
I've tried... (inside the class brackets)
public String mTitle() {
return mTitle;
}
...which throws the error:
./PictureBook.java:4: cannot find symbol
symbol : variable mTitle
location: class PictureBook
return mTitle;
^
1 error
I've also tried "return Title" instead of "return mTitle." I've tried cutting and pasting everything from the FunFacts project in and changing "fact" and "facts" to "title" and "titles" (removing the RandomNumber generator, because that would require a class I'm not sure I can call from the challenge interface) and that doesn't work either.
I just can't seem to get past this exercise. Any help would be appreciated. Thanks!
Molly Brower
1,915 PointsVarghese Joseph: We were both trying something far more complicated than this challenge actually calls for. Think of this as just an ordinary string in pretty much any language, but use Java conventions (specify it as public, capitalize String). No brackets or parentheses are required. So...
public String mTitle = "string";
varghesejoseph
824 PointsThanks Molly.
varghesejoseph
824 Pointsvarghesejoseph
824 PointsThanks for your reply. I tried the first one and the second one and I got this error message below
Make sure you are declaring a member variable in the class named 'mTitle'.