Debugging the application
We simply ran the application in
the simulator and the debugger wasn't involved. Debugging an
application is an essential part of the development process in order to
find and fix bugs that are an inevitable part of the application
development process. Eclipse provides a robust debugging environment
with many tools to make it as easy as possible. You've already seen the
simulator, which is also integrated into the debug process of Eclipse.
With Eclipse and the BlackBerry simulator, you can simulate and debug
your application very effectively.
So now, let's see these tools in action. What better
way than to actually see a bug in the application. However, as this
application is one of the samples and has already been debugged, you
will have to introduce a bug to use.
Starting the debugger
As
we said before, the first step is to actually introduce a bug. This
application is so simple that it was actually hard to decide how best to
do this! Simple is always best though, so for this exercise let's add
something that is obviously a bug. Passing a null value to the add method will work nicely for this purpose. Add the following code into the constructor of HelloWorldScreen at the end of the method, add(null);
When you are done, it should look like this:
The
next step is to start debugging the application. On the toolbar is an
icon with a bug-like image on it. You can also start debugging the
application by clicking on the Run menu item on the Debug menu. Click on the Debug toolbar button to start debugging the application.
When
you use Eclipse to debug for the first time, you will see a dialog like
the next one asking how you want to debug the application. This dialog
is shown only the first time you start the debugger, but you can change
it later if need be. We want to use the simulator, so select BlackBerry Simulator from the list and click on OK.
At
this point, the debug server is starting and the simulator is getting
set up. This process takes a lot more time than just running the
simulator by itself. It can take more than a minute to get all set.
During this time, the simulator will display a wait screen like the one
shown in the following screenshot and will not be usable.
Once it is all set up, the simulator will be shown and look the same as it did before.
What just happened?
OK, so now we have the simulator actually running and debugging the HelloWorldDemo sample application. To get here we only had to do a couple of things.
After setting things up, we actually launched the
simulator and debugger by clicking on the debug icon on the toolbar. You
may have noticed that the toolbar icon has a small down arrow next to
it. If you click on the arrow, a small menu will be displayed with
additional debugging options such as those we also saw in the "Debug As"
dialog. We aren't going to use them, so if you accidently click on the
arrow, just click on the bug icon or click away to close the menu up.
Before an application can be debugged it
must be compiled and built. Like most common IDEs, starting the debugger
will automatically build the application if it needs to be done. We did
change the code by introducing the bug, but otherwise there shouldn't
be any errors so that this build should be quick and event free.