Home Step 02 Step 04

Compiling, running, and debugging tutorial

Step 3: Fixing compiler errors

In this step of the tutorial, you will find and fix two compiler errors. In Step 2, you ran the program and compiler errors were displayed on the Compiler tab of the message pane.

To find and fix compiler errors,

  1. Double-click the first error on the Compiler tab:

         "Frame1.java" Error #300: constructor Double() not found
         in class java.lang.Double at line 39, column 31

    JBuilder positions the cursor on line 39, column 31 in the editor, the location of the error.

    The error message indicates that the Java class java.lang.Double does not contain a parameterless constructor. The highlighted statement is attempting to create a new Double object that does not have a parameter. If you look at the constructors in the java.lang.Double class, you'll see that all constructors require a parameter. Additionally, if you look a few lines further on in the program, you'll see that the Double object, valueTwoDouble, is constructed with an initial value of 0.0.

    Tip: Position the cursor between the parenthesis and press Ctrl+Shift+Space to display ParameterInsight, JBuilder's pop-up window that displays the required parameter type. You can also right-click the Double() method and choose Browse Symbol to open the source in the editor.

  2. Insert 0.0 between the parenthesis on line 39. The statement will now read:

         Double valueOneDouble = new Double(0.0)

    Tip: The content pane status bar now displays the word Modified, indicating that you've made changes to the file.

  3. Click the Save All button    on the toolbar.

  4. Click the Run Project button    on the toolbar. The program is recompiled. Because you fixed the first compiler error, it is no longer displayed on the Compiler tab.

  5. Double-click the first error on the Compiler tab:

         "Frame1.java" Error 300: variable subtractresultDisplay not found
         in class DebugTutorial.Frame1 at line 244, column 5

    This error indicates that the variable subtractresultDisplay in line 243 has not been defined.

  6. Choose Search|Find to display the Find/Replace Text dialog box.

    Tip: If the Find command is dimmed, click the file you want to search in and then choose Search|Find.

  7. Enter subtractresultDisplay in the Text To Find field. Make sure the Case Sensitive option is turned off. Click the Search From Start Of File option to start the search from the beginning of the file.

  8. Click Find All. The results of the search are displayed on the Search Results tab of the message pane.

    Notice that two of the three references to this label are subtractResultDisplay; there is an uppercase R in Result. Casing is critical in Java: subtractresultDisplay is not the same as subtractResultDisplay.

  9. Double-click the incorrect word in the Search Results tab to move the cursor to the word in the editor. JBuilder highlights the word.

  10. Change subtractresultDisplay to subtractResultDisplay.

  11. Right-click the Search Results tab and choose Remove "Search Results" Tab to close the search results.

To use CodeInsight to fix a compiler error,

  1. Double-click the next compiler error in the Compiler tab. This error indicates that there is no setTest() method in javax.swing.JLabel.

         "Frame1.java" Error #300: method setTest(java.lang.String) not
         found in class javax.swing.JLabel at line 255, column 27

    JBuilder positions the cursor on line 255, column 27.

  2. Press Ctrl+Space while the cursor is positioned after the dot (.). This will display the CodeInsight pop-up window that displays available member functions.

    Note: If the pop-up window is not displayed, choose the Keystrokes button on the CodeInsight page of the Editor Options dialog box (Tools|Editor Options). Use the keystrokes that are defined for your editor or customize them. For more information, see the topic called "Keymaps for editor emulations."

  3. Scroll through the window using the arrow keys. Those items that are bolded are in this class. The items with lines through them have been deprecated. The grayed-out items are inherited, but are available for use.

  4. Search for setText by typing setText or scrolling. Once selected, double-click it or press Enter. The setText() method is inserted in the editor after the dot, replacing the incorrect setTest method name. A tool tip displays the expected method parameter type.

Saving files and running the program

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

  2. Click the Run Project button    on the toolbar. The program runs and the UI is displayed.

  3. Enter values into the program's Value 1 and Value 2 input fields. Press the Compute Values button. The values are computed and displayed. However, if you look carefully at computed results, you'll see that there are some runtime errors; the program compiles and runs but gives incorrect results. You will find and fix these errors in the next steps.

  4. Choose File|Exit to exit the application.

  5. Right-click the Application1 tab in the message pane, and choose Remove "Application1" Tab.

Home Step 02 Step 04