2 3debugging Help SheetFEB5
2 3debugging Help SheetFEB5
Breakpoints
You can add and remove breakpoints by clicking in the left side of the code area. Set the
breakpoint to where you want the code to stop. In this video we are breaking the code (or
halting its execution) at TheGame.java file’s setupBeginning method, where mBallX value is
assigned.
To remove a breakpoint click on it again.
Starting the code takes a little longer, and the code runs a bit slower than normal.
It will prompt a dialog asking to select a device. Select your emulator from the list (At this
point it also allows you to launch a different emulator if you wish) and click ‘OK’.
Next you will see the emulator displaying a message similar to Figure 5.
Once the game is loaded it will show a screen similar to Figure 6 on your emulator.
Now click on the emulator screen. It will now execute the ‘setupBeginning’ method and it
will halt the execution of the code at the break point we have set in the ‘setupBeginning’
method (Figure 7).
Now click on the emulator screen. It will now execute the ‘setupBeginning’ method and it
will halt the execution of the code at the break point we have set in the ‘setupBeginning’
method.
Note: the values of mCanvasWidth and mCanvasHeight can vary on the emulator you have
selected.
With this setup (mCanvasWidth being 320) I expect my mBallX will be 160 once the
statement
mBallX = mCanvasWidth / 2;
Press F8 (Step Over) to execute the next line of code. This will execute the line
mBallX = mCanvasWidth / 2;
Now view the variable value of mBallX.
You will see that mBallX is assigned with half of the mCanvasWidth value as expected. You
can use F8 again and again to execute the program statement by statement.