1 00:00:00,380 --> 00:00:03,740 I've got some really bad news for you, you aren't perfect. 2 00:00:04,780 --> 00:00:05,355 None of us are. 3 00:00:05,355 --> 00:00:08,180 You're gonna make mistakes. 4 00:00:08,180 --> 00:00:11,430 In fact, I'm still constantly making mistakes. 5 00:00:12,840 --> 00:00:14,690 There are gonna be errors in your code. 6 00:00:14,690 --> 00:00:18,178 There are going to be lots of errors in your code. 7 00:00:18,178 --> 00:00:20,640 In fact, [LAUGH] any time you watch someone coding and 8 00:00:20,640 --> 00:00:22,970 are impressed by their lack of mistakes, 9 00:00:22,970 --> 00:00:28,220 is almost certainly because they spent a lot of time making mistakes and they've 10 00:00:28,220 --> 00:00:32,100 learned to avoid the common pitfalls that we all, as developers, fall into. 11 00:00:33,240 --> 00:00:34,950 The sooner you can view mistakes and 12 00:00:34,950 --> 00:00:38,940 errors as a positive result of your own experimentation, the quicker you will be 13 00:00:38,940 --> 00:00:42,400 on the road to mastering a language and with much less frustration. 14 00:00:43,470 --> 00:00:46,030 Remember, if you aren't failing, you aren't learning. 15 00:00:47,160 --> 00:00:48,760 There are different types of errors. 16 00:00:48,760 --> 00:00:50,790 The most common errors are syntax errors and 17 00:00:50,790 --> 00:00:54,980 they can be very frustrating as you're first diving into a language. 18 00:00:54,980 --> 00:00:58,950 The good news is that Java compiler is very good at reporting these, 19 00:00:58,950 --> 00:01:01,870 and usually, the answer is pretty clear. 20 00:01:01,870 --> 00:01:03,350 Now, let's go break stuff. 21 00:01:04,730 --> 00:01:06,620 Hopefully, you haven't had any errors yet. 22 00:01:06,620 --> 00:01:08,530 Let's intentionally make one. 23 00:01:08,530 --> 00:01:11,110 I'm gonna misspell the string declaration here, 24 00:01:11,110 --> 00:01:14,730 making it spelled as the popular singer, Sting. 25 00:01:14,730 --> 00:01:16,350 Let's see what happens. 26 00:01:16,350 --> 00:01:19,740 Now press the up arrow and get our information back here. 27 00:01:21,700 --> 00:01:26,190 And we will see here that we got an error that says, cannot find symbol. 28 00:01:26,190 --> 00:01:29,430 And if you look, this shows the line number which is 13, line 13, 29 00:01:29,430 --> 00:01:33,270 and it says the error, cannot find symbol. 30 00:01:34,530 --> 00:01:38,657 And then also underneath here there's an arrow that's pointing up exactly where 31 00:01:38,657 --> 00:01:39,505 the problem is. 32 00:01:39,505 --> 00:01:44,117 So that is wonderful, but now you saw me make the change from string, but 33 00:01:44,117 --> 00:01:49,107 if you didn't and if for some reason you didn't see the obvious arrow pointing 34 00:01:49,107 --> 00:01:53,806 at the lead singer of the Police, one place we could turn is the Internet. 35 00:01:53,806 --> 00:01:56,970 Java's been around for a long time. 36 00:01:56,970 --> 00:01:59,570 It'll be hard to stump Google with a Java problem. 37 00:01:59,570 --> 00:02:00,930 It's heard them all. 38 00:02:00,930 --> 00:02:01,602 Let's give it a spin. 39 00:02:01,602 --> 00:02:05,450 I'm gonna copy this, cannot find symbol error, 40 00:02:08,460 --> 00:02:10,600 then I'm gonna swing over to Google and I'm gonna paste that. 41 00:02:13,840 --> 00:02:17,540 So we got some results here, we have 482,000 results. 42 00:02:17,540 --> 00:02:19,190 Let's go ahead and look at the first one here. 43 00:02:19,190 --> 00:02:19,870 I'm feeling lucky. 44 00:02:21,340 --> 00:02:23,990 Okay, when a Java program is being compiled, 45 00:02:23,990 --> 00:02:26,600 the compiler creates a list of identifiers to use. 46 00:02:26,600 --> 00:02:31,830 If it can't find what an identifier refers to, it can't complete the compilation. 47 00:02:31,830 --> 00:02:34,840 This is what we're seeing, this is what the cannot 48 00:02:34,840 --> 00:02:37,490 find symbol error message is saying, that's what we're getting, so it doesn't 49 00:02:37,490 --> 00:02:42,130 have enough information to piece together what the Java code wants to execute. 50 00:02:42,130 --> 00:02:46,340 Okay, so some possible causes, trying to use a variable without declaring it. 51 00:02:46,340 --> 00:02:49,320 Well, that's not the case cuz that our declaration line. 52 00:02:49,320 --> 00:02:53,860 Misspelling a class or method name, possible that we misspelled. 53 00:02:53,860 --> 00:02:58,280 Let's go back and take a, that's right, we did misspell it. 54 00:02:58,280 --> 00:03:02,780 So let's go ahead and put an r back in there. 55 00:03:02,780 --> 00:03:06,840 Okay, so there's an example of a cannot find symbol. 56 00:03:06,840 --> 00:03:09,719 Another one that is very common is this, 57 00:03:09,719 --> 00:03:14,810 if we make this a lowercase s here on the String, then we'll save this. 58 00:03:14,810 --> 00:03:17,554 Let's go ahead and I'll run it again. 59 00:03:17,554 --> 00:03:22,279 Okay, we get a cannot find symbol in its own string, a string is spelled right, so 60 00:03:22,279 --> 00:03:24,895 let's go ahead let's jump back over there. 61 00:03:24,895 --> 00:03:26,570 Let's search for that specifically. 62 00:03:26,570 --> 00:03:32,431 So we have cannot find symbol in string. 63 00:03:32,431 --> 00:03:36,483 Okay, so 998,000 results here. 64 00:03:36,483 --> 00:03:39,627 I scroll down and I see, well, this one's from Oracle. 65 00:03:39,627 --> 00:03:42,726 That's great cuz Oracle's the company that currently makes Java so 66 00:03:42,726 --> 00:03:45,085 let's take a look and see what they have to say here. 67 00:03:45,085 --> 00:03:47,965 This person is having a similar problem that we are. 68 00:03:47,965 --> 00:03:50,770 Java file's not recognizing string as in private string name. 69 00:03:50,770 --> 00:03:53,156 What is going on and could this be an install problem? 70 00:03:55,928 --> 00:03:57,920 Capital letter S. 71 00:03:57,920 --> 00:04:00,380 Everything in Java's case sensitive, okay, great. 72 00:04:00,380 --> 00:04:02,940 So let's go back and we can fix that. 73 00:04:04,430 --> 00:04:05,650 Perfect. 74 00:04:05,650 --> 00:04:08,080 So that's an example of what you can do when you get an error. 75 00:04:08,080 --> 00:04:11,720 Remember, just go out and search for it, come to the forums if you need to as well. 76 00:04:12,880 --> 00:04:16,510 So now we know that we will make syntax errors and what they'll look like. 77 00:04:17,645 --> 00:04:20,230 I'll show off some more common gotchas in logic and 78 00:04:20,230 --> 00:04:23,810 other runtime errors as we dig a little deeper into our program. 79 00:04:23,810 --> 00:04:27,150 I've pointed out the seemingly endless resources on the Internet, but 80 00:04:27,150 --> 00:04:31,780 I want to encourage you once again to use the treehouse community to your advantage. 81 00:04:31,780 --> 00:04:36,050 Your fellow classmates are here to help and by sharing your errors, 82 00:04:36,050 --> 00:04:38,980 it actually gives someone else the ability to learn from your mistakes.