Compiling, running, and debugging tutorial
Syntax errors do not meet the syntactical requirements of the Java language. JBuilder identifies these errors before you compile. They are listed in the Errors
folder of the structure pane. If you try to compile the program without fixing these syntax errors, JBuilder will display the errors in the message pane. The program cannot be compiled until these errors are fixed.
In this step, you will find the syntax errors in the sample program and fix them. For more information on JBuilder's error messages, see the topic called "Error messages."
To find and fix syntax errors,
Errors
folder in the structure pane.
Three errors are listed. The first error:
';' expected at line 38
indicates that a semi-colon is missing from the end of line 38.
illegal start of type at line 222
JBuilder moves the cursor to line 222 in the editor. This error is a little trickier to decipher. The message means that a type identifier was expected at this point in the program, but was not found. Notice that line 222 starts with the keyword else,
and that line 221 consists of a single closing brace. If you read the code before line 222, you'll notice the beginning of an if
statement on line 219. In Java, an if
statement must include an opening and closing brace. However, if you look on line 219, you'll see that the opening brace is missing.
if (valueOneOddEven) {
The remaining two syntax errors are removed from the structure pane.
Sometimes it takes a bit of detective work to correct syntax errors. Often, fixing one syntax error will fix several errors listed in the structure pane. In this case, for example, the third syntax error was:
'class' or 'interface' expected at line 228
. Because the closing brace did not have a corresponding opening brace, JBuilder expected to find a class declaration after the close of the current method. However, when the opening brace was added, JBuilder could determine that the brace now had a match and that the next line of code was not in
error.
Ctrl + ]
.