Step 4: Using the Debugger to Debug the Application

Previous topic
Previous
Next topic
Next

Now that you have created an application that will run the UI, you will practice some simple debugging in JDeveloper as practice for debugging more complex applications.

You'll probably want to set a least one breakpoint before you start debugging, but it is not necessary. Setting a breakpoint in your source code instructs the debugger to pause at an exact location in the source code while debugging.

If you do not set a breakpoint, you can:

Once you have paused the debugger, you can control specifically how you want it to reenter your code, using the Debug menu, toolbar icons, or keyboard equivalents. The step operations available to you include:

Notes:

To set a breakpoint in your source code:

  1. Open Frame1.java in the Code Editor.

    If the file is closed, double-click its source node in the Navigator to open it in its default editor.

    Your source code should still be open. If it is, to bring the Code Editor for Frame1.java to the foreground, you can double-click its node in the Navigator, or select its entry (in this tutorial, marked with a number 2) in the document bar. Unless you have explicitly changed their numbering, any files you have opened are displayed in the document bar in the order you opened them.

  2. You can also cascade or tile your editor windows and navigate between them this way. To do so, from the main menu, choose Window | Cascade or one of the two tile options.

  3. In the gray margin of the editor, line numbers appear. Click the number beside the first line containing an if statement.

    Notice that Unverified breakpoint indicator appears in place of the line number, indicating that an unverified breakpoint has been set at this line in the source code. To remove a breakpoint, just click Unverified breakpoint indicator and the line number reappears.

  4. Display the Breakpoints window by choosing View | Debug Windows | Breakpoints. This window displays all the breakpoints set for this workspace or project.

To run the debugger on your source code:

  1. Click The Debug icon Debug in the toolbar to start the debugger.

    Note: If the Default Run Target dialog is displayed, you must select a Java class with a main method to use as the default. In this case, you would select the Application1.java class you created earlier. Click Browse and navigate to \Workspace1\Project1\src\package1. Select Application1.java and click Open. On the Default Run Target dialog, click OK to continue debugging.

A number of things now happen:

  1. When the application is run, select a status code from the combo box and click OK. Nothing happens because the code to display the status text in the text field is never executed. In the Code Editor, Current execution point indicator appears in the margin at the line where you set your breakpoint indicating the current execution point.
  2. Click The Step Over icon Step Over  in the toolbar to step to the next line of code. The Current execution point indicator moves to the next if statement. The Verfified breakpoint indicator verified breakpoint icon appears, indicating that your breakpoint is now validated.

    If you continue clicking The Step Over icon Step Over, you will continue moving through the code to the next executable line, stepping over, rather than into, the method calls.

  3. In the Smart Data window, expand the this and this$0 nodes. You can see each of the components and the classes they are based on. If you expand these further, you can see their properties and the property values.
  4. Click The Resume icon Resume  to continue running the rest of the program.

    If another breakpoint was set, the program continues to that point. Without breakpoints, the debugging process will complete when you terminate the application being debugged.

  5. Once your program has completed, the debugger process exits. When you close the application, a message to this effect appears in the Log tab within the Log window.

Now that you have practiced debugging, you are ready for the next task, Step 5: Compiling and Running the Application.