|
| 1 | +.. _Common Mistakes: |
| 2 | + |
1 | 3 | Common Mistakes |
2 | 4 | =============== |
3 | 5 |
|
| 6 | +Forgetting to declare your variables |
| 7 | +------------------------------------ |
4 | 8 |
|
5 | | - - **Forgetting to declare your variables.** |
6 | | - |
7 | | - :: |
| 9 | +:: |
8 | 10 |
|
9 | | - Histo.java:21: cannot find symbol |
10 | | - symbol : variable count |
11 | | - location: class Histo |
12 | | - count = new ArrayList<Integer>(10); |
13 | | - ^ |
| 11 | + Histo.java:21: cannot find symbol |
| 12 | + symbol : variable count |
| 13 | + location: class Histo |
| 14 | + count = new ArrayList<Integer>(10); |
| 15 | + ^ |
14 | 16 |
|
15 | | - - **Not importing a class**: |
| 17 | +Not importing a class |
| 18 | +--------------------- |
16 | 19 |
|
17 | | - :: |
| 20 | +:: |
18 | 21 |
|
19 | | - Histo.java:9: cannot find symbol |
20 | | - symbol : class Scanner |
21 | | - location: class Histo |
22 | | - Scanner data = null; |
23 | | - ^ |
| 22 | + Histo.java:9: cannot find symbol |
| 23 | + symbol : class Scanner |
| 24 | + location: class Histo |
| 25 | + Scanner data = null; |
| 26 | + ^ |
24 | 27 |
|
25 | | - - **Forgetting to use the new keyword to create an object.** Here’s |
26 | | - an example of the error message that occurs when you forget to |
27 | | - use the new keyword. Notice that the message is pretty unhelpful. |
28 | | - Java *thinks* you are trying to call the Method Scanner, but |
29 | | - there are two problems. First Scanner is not really a method it |
30 | | - is a constructor.: |
| 28 | +Forgetting to use the new keyword to create an object |
| 29 | +----------------------------------------------------- |
| 30 | +Here’s an example of the error message that occurs when you forget to |
| 31 | +use the new keyword. Notice that the message is pretty unhelpful. |
| 32 | +Java *thinks* you are trying to call the Method Scanner, but |
| 33 | +there are two problems. First Scanner is not really a method it |
| 34 | +is a constructor.: |
31 | 35 |
|
32 | | - :: |
| 36 | +:: |
33 | 37 |
|
34 | | - Histo.java:14: cannot find symbol |
35 | | - symbol : method Scanner(java.io.File) |
36 | | - location: class Histo |
37 | | - data = Scanner(new File("test.dat")); |
38 | | - ^ |
| 38 | + Histo.java:14: cannot find symbol |
| 39 | + symbol : method Scanner(java.io.File) |
| 40 | + location: class Histo |
| 41 | + data = Scanner(new File("test.dat")); |
| 42 | + ^ |
39 | 43 |
|
40 | | - - **Forgetting a Semicolon**: |
| 44 | +Forgetting a Semicolon |
| 45 | +---------------------- |
41 | 46 |
|
42 | | - :: |
| 47 | +:: |
43 | 48 |
|
44 | | - Histo.java:19: |
45 | | - ';' expected |
46 | | - System.exit(0); |
47 | | - ^ |
| 49 | + Histo.java:19: |
| 50 | + ';' expected |
| 51 | + System.exit(0); |
| 52 | + ^ |
48 | 53 |
|
49 | | - - Forgetting to declare the kind of object in a container.: |
| 54 | +Forgetting to declare the kind of object in a container |
| 55 | +------------------------------------------------------- |
50 | 56 |
|
51 | | - :: |
| 57 | +:: |
52 | 58 |
|
53 | | - Note: Histo.java uses unchecked or unsafe operations. Note: |
54 | | - Recompile with -Xlint:unchecked for details. |
| 59 | + Note: Histo.java uses unchecked or unsafe operations. Note: |
| 60 | + Recompile with -Xlint:unchecked for details. |
0 commit comments