Home Step 01 Step 03

Compiling, running, and debugging tutorial

Step 2: Fixing syntax errors

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,

  1. Expand the 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.

  2. Click the error in the structure pane. JBuilder moves the cursor to line 38 in the editor. If you single-click the error message, JBuilder highlights the line of the code where the error occurred. A double-click places the cursor in the column where the error occurred.

    Tip: The content pane's status bar displays the line and column number, as well as the insert mode.

  3. Add a semi-colon to the end of the line. You've fixed the error, and it is removed from the structure pane.

  4. Click the next error in the structure pane:

         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.

  5. Add an opening brace to the end of line 219. The completed line of code will look like this:

         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.

Tip: You can find matching braces by moving your cursor to the left of the starting or ending brace and pressing Ctrl + ].

Saving files and running the program

To save your changes and run the program,
  1. Click the Save All button    on the main toolbar.

  2. Click the Run Project button    on the toolbar. The program does not run but displays compiler errors on the Compiler tab of the message pane. Go to Step 3 to find and fix these errors.

Home Step 01 Step 03