Skip to content

Commit f245fe6

Browse files
authored
Merge pull request #359 from DieuMerci225/chapter9.3
Added listing tag to make the text more organized
2 parents 529a6c4 + 437cd88 commit f245fe6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

source/ch9_commonmistakes.ptx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@
8989
<title>Forgetting to declare your variables</title>
9090
<p>
9191
In Python, you can use a variable without declaring it first, but in Java, you must declare all variables before using them.
92-
If you try to use a variable that has not been declared, the Java compiler will give you an error message like this:
92+
<xref ref="undeclared-variable" text="type-global"/> shows If you try to use a variable that has not been declared, the Java compiler will give you an error message like this:
9393
</p>
94+
<listing xml:id="undeclared-variable">
9495
<program language="java" interactive="activecode" line-numbers="yes">
9596
<code>
9697
import java.util.ArrayList; // Import necessary class
@@ -110,6 +111,7 @@
110111
} // End of class
111112
</code>
112113
</program>
114+
</listing>
113115
<p>
114116
The 'cannot find symbol' error for the variable <c>count</c> on line 6 indicates that <c>count</c> was used before it was declared within the <c>Histo</c> class. In Java, all variables must be explicitly declared with a data type (e.g., <c>int</c>, <c>String</c>, <c>ArrayList&lt;Integer&gt;</c>) before they can be assigned a value or referenced in any way. The arrow in the error message points to where the undeclared variable <c>count</c> was first encountered. To resolve this, <c>count</c> needs to be declared with its appropriate type (e.g., <c>ArrayList&lt;Integer&gt; count;</c>) before any attempt to initialize or use it.
115117
</p>

0 commit comments

Comments
 (0)