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