5 Debugging Android Apps

In this chapter, you will find out what to do when apps get buggy. You will learn how to use Logcat, Android Lint, and the debugger that comes with Android Studio.

To practice debugging, the first step is to break something. In MainActivity.kt, comment out the code in onCreate(Bundle?) where you find questionTextView by its ID.

Listing 5.1  Commenting out a crucial line (MainActivity.kt)

override fun onCreate(savedInstanceState: Bundle?) {
    ...
    trueButton = findViewById(R.id.true_button)
    falseButton = findViewById(R.id.false_button)
    nextButton = findViewById(R.id.next_button)
    // questionTextView = findViewById(R.id.question_text_view)
    ...
}

Run GeoQuiz and see what happens. The app will crash ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.