YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 43 lines · added Dec 14, 2015

Report a problem
What's wrong?
Advertisement

English transcript

I asked you to determine the bug in each of these lines of code.
Hopefully, you were able to do it by just looking at that line.
For this solution video, I'm going to enter these lines of code into
Android Studio so that you can see what error Android Studio would give us, and
we're going to fix it as well so that there are no errors.
I temporarily commented out this line of code using the double forward slash so
that it doesn't show that there's a red error every time.
We'll switch back to the code we had before, but
I just wanted a place where I could add these test strings.
If I type in string title = "Today's Specials", I get an error.
It says that it can't resolve the symbol string.
That's because Java doesn't recognize the type string with lowercase s.
It needs to have a capital S.
Now it recognizes this data type, and there's no errors.
There's an error on the second line, but
I'm going to comment it out with a double forward slash.
That way the computer won't try to compile that line.
Technically this string isn't going to go into our app, so
we don't need it to work with the rest of our code.
If I type in specialOfTheDay = "Cafe Latte", I also get an error.
It says cannot resolve symbol specialOfTheDay.
That's because this variable was not created earlier.
This is the first time we're using it, and so
we need to specify the data type in front of it.
So we'll say String specialOfTheDay = "Caffe Latte",
and that fixes the problem.
Now I've typed in String nutritionInfo = "500 calories or less.
Under the string here,
I get a red underline that says illegal line and in string literal.
I was trying to create a string literal here, but I forgot the end quote.
So we need to add that, and that fixes the problem.
The last one is String drink name = "iced coffee".
The word name is highlighted in red, and
I get an error saying it cannot resolve the symbol name.
The reason is because a variable name should be in camelCase with no spaces.
So I need to get rid of the space here, and if there's two words,
you can just capitalize the beginning of the second word.
And that fixes the error.
For the name of the drink, you might want to capitalize the I or
the C here, but it's really up to you.
Anything you put in the double quotes is your choice, and
the Java compiler won't complain about those types of errors.
Great, you've really mastered how to create strings in Java now.

Need subtitles from another video?