Skip to content

Commit 437cd88

Browse files
nshizirungudieumerci@gmail.comnshizirungudieumerci@gmail.com
authored andcommitted
Added listing tag to make the text more organized
1 parent c37c607 commit 437cd88

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
@@ -87,8 +87,9 @@
8787
<title>Forgetting to declare your variables</title>
8888
<p>
8989
In Python, you can use a variable without declaring it first, but in Java, you must declare all variables before using them.
90-
If you try to use a variable that has not been declared, the Java compiler will give you an error message like this:
90+
<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:
9191
</p>
92+
<listing xml:id="undeclared-variable">
9293
<program language="java" interactive="activecode" line-numbers="yes">
9394
<code>
9495
import java.util.ArrayList; // Import necessary class
@@ -108,6 +109,7 @@
108109
} // End of class
109110
</code>
110111
</program>
112+
</listing>
111113
<p>
112114
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.
113115
</p>

0 commit comments

Comments
 (0)