Introducing Eclipse perspectives
Eclipse uses the term perspective
to mean a saved configuration of views and their placement on the
workbench. So far, you've seen only the "Java" perspective that is used
when developing applications. This perspective contains things such as a
task list, console output, and documentation views, but there is
another important perspective that we will encounter next — the Debug perspective.
The views in the Java perspective aren't
particularly useful when you are debugging an application, so they are
hidden and an all new set of windows is displayed once you switch to the
Debug perspective. These views include the call stack, variables, and
watch windows that are more useful when trying to look at the current
state of the running application. Let's take a look at that right now by
going back to the simulator and finding that bug we made.
Time for action - changing the perspective
After
starting the application under the debugger you left the simulator
still running and waiting to be used. Go back to the simulator and find
the HelloWorldDemo application and activate it by pressing the F9 or Enter key.
Unlike
before, this time you see a new dialog being displayed right away.
Generally, you don't want to see this dialog each time so check the Remember my decision checkbox and then click on the Yes button.
Now,
Eclipse looks very different than it did just a moment ago. Eclipse has
been brought to the foreground and is now showing the Debug perspective.
The code view isn't showing any of the HelloWorldDemo application though because the actual error occurred deep inside the framework.
Because
the actual bug happened deep inside a framework method, the source code
for that method can't be shown. Instead, you need to look at the call
stack and find the last point where the code in the application was
executed. Click on the item labeled HelloWorldScreen.<init>() line:79; this should display the source code for HelloWorldDemo.java in the code view. Now, place the cursor on your bug at line 79.
As we
know where the problem is, it's time to go and fix it. There are some
tricks to keep on debugging the application, but for now let's just stop
debugging the application. Do this by simply closing the simulator by
using the standard methods.
Now
that the debugging session is over I bet you expected Eclipse to change
the screen back to normal. I did too, but this is not the case. To
change the perspective back to the Java perspective, just click on the Java button on the perspective toolbar above the variables view.
What just happened?
How's that for some fun? In this section, you did
some basic debugging by creating a bug in the source and then running
the application in the simulator. You saw how the debugger stopped when
the bug was encountered and used the call stack to find the source of
the problem.
There are a lot of other things that you could have
done once the debugger was active. Eclipse has a lot of tools that make
the interactive debugger powerful and useful. The call stack is just one
of the many windows available on the Debug perspective. The variables
and watches allow you to see the current state of variables at each step
in the call stack.
Additionally, above the call stack as part of the Debug window you will find the Run menu that gives you all the normal run operations. There are buttons for each operation such as Step Over, Step In, and Step Out as well as Run and others. Furthermore, there are special actions available on the right-click menu such as Set Next Statement or Run to line, which can be very helpful in some situations.
One of the surprises is the discovery of the Debug
perspective and how it changes the way Eclipse looks and what windows
are displayed. This change is a little startling if you aren't already
familiar with it and having to change it back can also be confusing when
getting started with Eclipse. Perspectives are an integral part of the
debugging process though, and it won't be unusual for long.