Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Errors are bound to happen. In this video we discuss what to do when they occur.
-
0:00
I've got some really bad news for you, you aren't perfect.
-
0:04
None of us are.
-
0:05
You're gonna make mistakes.
-
0:08
In fact, I'm still constantly making mistakes.
-
0:12
There are gonna be errors in your code.
-
0:14
There are going to be lots of errors in your code.
-
0:18
In fact, [LAUGH] any time you watch someone coding and
-
0:20
are impressed by their lack of mistakes,
-
0:22
is almost certainly because they spent a lot of time making mistakes and they've
-
0:28
learned to avoid the common pitfalls that we all, as developers, fall into.
-
0:33
The sooner you can view mistakes and
-
0:34
errors as a positive result of your own experimentation, the quicker you will be
-
0:38
on the road to mastering a language and with much less frustration.
-
0:43
Remember, if you aren't failing, you aren't learning.
-
0:47
There are different types of errors.
-
0:48
The most common errors are syntax errors and
-
0:50
they can be very frustrating as you're first diving into a language.
-
0:54
The good news is that Java compiler is very good at reporting these,
-
0:58
and usually, the answer is pretty clear.
-
1:01
Now, let's go break stuff.
-
1:04
Hopefully, you haven't had any errors yet.
-
1:06
Let's intentionally make one.
-
1:08
I'm gonna misspell the string declaration here,
-
1:11
making it spelled as the popular singer, Sting.
-
1:14
Let's see what happens.
-
1:16
Now press the up arrow and get our information back here.
-
1:21
And we will see here that we got an error that says, cannot find symbol.
-
1:26
And if you look, this shows the line number which is 13, line 13,
-
1:29
and it says the error, cannot find symbol.
-
1:34
And then also underneath here there's an arrow that's pointing up exactly where
-
1:38
the problem is.
-
1:39
So that is wonderful, but now you saw me make the change from string, but
-
1:44
if you didn't and if for some reason you didn't see the obvious arrow pointing
-
1:49
at the lead singer of the Police, one place we could turn is the Internet.
-
1:53
Java's been around for a long time.
-
1:56
It'll be hard to stump Google with a Java problem.
-
1:59
It's heard them all.
-
2:00
Let's give it a spin.
-
2:01
I'm gonna copy this, cannot find symbol error,
-
2:08
then I'm gonna swing over to Google and I'm gonna paste that.
-
2:13
So we got some results here, we have 482,000 results.
-
2:17
Let's go ahead and look at the first one here.
-
2:19
I'm feeling lucky.
-
2:21
Okay, when a Java program is being compiled,
-
2:23
the compiler creates a list of identifiers to use.
-
2:26
If it can't find what an identifier refers to, it can't complete the compilation.
-
2:31
This is what we're seeing, this is what the cannot
-
2:34
find symbol error message is saying, that's what we're getting, so it doesn't
-
2:37
have enough information to piece together what the Java code wants to execute.
-
2:42
Okay, so some possible causes, trying to use a variable without declaring it.
-
2:46
Well, that's not the case cuz that our declaration line.
-
2:49
Misspelling a class or method name, possible that we misspelled.
-
2:53
Let's go back and take a, that's right, we did misspell it.
-
2:58
So let's go ahead and put an r back in there.
-
3:02
Okay, so there's an example of a cannot find symbol.
-
3:06
Another one that is very common is this,
-
3:09
if we make this a lowercase s here on the String, then we'll save this.
-
3:14
Let's go ahead and I'll run it again.
-
3:17
Okay, we get a cannot find symbol in its own string, a string is spelled right, so
-
3:22
let's go ahead let's jump back over there.
-
3:24
Let's search for that specifically.
-
3:26
So we have cannot find symbol in string.
-
3:32
Okay, so 998,000 results here.
-
3:36
I scroll down and I see, well, this one's from Oracle.
-
3:39
That's great cuz Oracle's the company that currently makes Java so
-
3:42
let's take a look and see what they have to say here.
-
3:45
This person is having a similar problem that we are.
-
3:47
Java file's not recognizing string as in private string name.
-
3:50
What is going on and could this be an install problem?
-
3:55
Capital letter S.
-
3:57
Everything in Java's case sensitive, okay, great.
-
4:00
So let's go back and we can fix that.
-
4:04
Perfect.
-
4:05
So that's an example of what you can do when you get an error.
-
4:08
Remember, just go out and search for it, come to the forums if you need to as well.
-
4:12
So now we know that we will make syntax errors and what they'll look like.
-
4:17
I'll show off some more common gotchas in logic and
-
4:20
other runtime errors as we dig a little deeper into our program.
-
4:23
I've pointed out the seemingly endless resources on the Internet, but
-
4:27
I want to encourage you once again to use the treehouse community to your advantage.
-
4:31
Your fellow classmates are here to help and by sharing your errors,
-
4:36
it actually gives someone else the ability to learn from your mistakes.
You need to sign up for Treehouse in order to download course files.
Sign up