Day97 of #100DaysOfCode

Day97 of #100DaysOfCode

Unit 4: Internet

Pathway 2: Get and Display Data

https://developer.android.com/courses/android-basics-kotlin/course

  • If necessary, we will introduce the bug by changing 4 to 5 in the repeat loop.
repeat(4) {
...
}
  • Place a new breakpoint on the line with the repeat statement.
  • Right click on the red breakpoint icon. A menu will appear with a few options, such as whether or not the breakpoint is enabled. A disabled breakpoint still exists, but won’t be triggered at runtime. We also have an option to add a Kotlin expression that if it evaluates to true, the breakpoint will be triggered. For example, if we used the expression denominator > 3, the breakpoint would only be triggered on the first iteration of the loop. To only trigger the breakpoint when the app is potentially going to divide by zero, set the expression to denominator == 0. The options for the breakpoint should look like the following:
  • Run the app using Run > Debug ‘app’ and observe that the breakpoint is reached.
  • We can see that the denominator is already 0. The breakpoint was only triggered when the condition was met, saving the time and effort to step through the code.
  • Like before, we see that the bug is caused by the loop executing one too many times, where the denominator was set to 0.
  • In the debug view, to the right of the variables pane, there should be another empty pane called Watches. Click the plus
  • Button in the top left corner. We may see a menu option that says New Watch.
  • Type the name of the variable, denominator, in the provided field and click enter.
  • Re-run the app with Run > debug ‘app’, and observe that when the breakpoint is hit, we’ll see the value of the denominator in the Watches pane.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store