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 trialMatthew Garcia
7,520 PointsNot sure of the problem: ./PictureBook.java:4: error: missing return statement } ^ 1 error
I followed the instructions, I believe. I don't know else to do from here. Any advice?
public class PictureBook {
public String mTitle () {
}
}
1 Answer
aakarshrestha
6,509 PointsSince the method is not a void method, it needs a return statement.
e.g:
public class PictureBook {
// Member variables (properties about the objects)
public String[] mTitles = {"God Father", "Iron Man"};
public String mTitle () {
String fact = "";
// Randomly select a fact
Random randomGenerator = new Random(); // construct a new random number generator
int randomNumber = randomGenerator.nextInt(mTitles.length);
fact = mTitles[randomNumber];
return fact;
}
}
Hope you got the idea now.
Happy Coding!
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsHi There! I just wanted to let you know that I formatted your code and changed your comment to an answer. To format it. I added three back-ticks (`) and the name of the language in the code block (in this case,
java
) above the code, and three back-ticks below the code.I also changed your comment to an answer. This allows it to be accepted as the best answer and upvoted if it is helpful.