0% found this document useful (0 votes)
45 views

2 3debugging Help SheetFEB5

This document introduces debugging basics like breakpoints, debugging an app, viewing variable values, and executing code line by line to view value changes using breakpoints and debug commands like Step Over. It includes figures to demonstrate setting a breakpoint, viewing variables, and debug controls.

Uploaded by

lubona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

2 3debugging Help SheetFEB5

This document introduces debugging basics like breakpoints, debugging an app, viewing variable values, and executing code line by line to view value changes using breakpoints and debug commands like Step Over. It includes figures to demonstrate setting a breakpoint, viewing variables, and debug controls.

Uploaded by

lubona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Begin programming:

Build your first mobile game

Debugging help sheet


This document will introduce you to the basics of debugging and is intended to
support the ‘Introduction to data types and variables’ video:

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.

Figure 1: Click to set up a breakpoint

After setting up the breakpoint it will look similar to Figure 2.

Figure 2: A breakpoint is setup

Have the emulator started and fully loaded up.

©University of Reading 2015 Thursday 5 February 2015 Page 1


Debug app
Instead of running the program using Run ‘app’ (the green triangle), start debugging by
pressing the little green bug (Debug ‘app’) shown in Figure 3.

Figure 3: Debug ‘app’

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’.

Figure 4: Choose Device dialog

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.

©University of Reading 2015 Thursday 5 February 2015 Page 2


Figure 5: Waiting for Debugger message

Figure 6: Emulator after loading the game

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).

©University of Reading 2015 Thursday 5 February 2015 Page 3


Figure 7: Execution halted at the breakpoint

Viewing variable values


All the variables that are available at present are shown in the Variables tab located bottom
half of the screen. But it only shows a few in the default view. Clicking on the arrow near
‘this’ in the variables tab will show all variable values. For the moment let us concentrate on
the variables mBallX and mBallY.

Figure 8: Variables and their values

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.

Execute code line by line

With this setup (mCanvasWidth being 320) I expect my mBallX will be 160 once the
statement
mBallX = mCanvasWidth / 2;

©University of Reading 2015 Thursday 5 February 2015 Page 4


gets executed. After the breakpoint we can run the code line by line in the debugger to view
the value changes. The debug commands for these can be found in the menu under Run
(Figure 9).

Figure 9: Debug Commands

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.

Figure 10: mBallX is assigned

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.

©University of Reading 2015 Thursday 5 February 2015 Page 5


On the side of the Debugger tab you will see controls that allow you to control your
application while debugging (Figure 11). Hover over the controls and you will be shown what
they are.

Figure 11: Controls – highlighted is stop

Useful to know: (0,0) location of a Bitmap is the top left corner.

©University of Reading 2015 Thursday 5 February 2015 Page 6

You might also like