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 trialMUZ140584 Heredity Mbundire
4,979 PointsThese two variables need to be initialized with empty strings to prevent an app crash. Do it!
string title; string author;
String title;
String author;
1 Answer
Daniel Hartin
18,106 PointsHi
It is usually good practice to initialize variables with a default value, this is so if for any reason your variable doesn't get given a value in your code it already has a value of some kind to show or work with.
As the variable type is String we can initialize them using empty double quotes as shown below.
String title = "";
String author = "";
Hope this helps
Daniel
Jonthue Michel
1,462 PointsJonthue Michel
1,462 PointsI get it now, so it is not wise to just leave String title and then end it off with ;. But by putting String title = ""; then it can be set for default without messing up or crashing. Thanks!