4Debugging 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 Eclipse.

To practice debugging, the first step is to break something. In QuizActivity.java, comment out the code in onCreate(Bundle) where you pull out mQuestionTextView.

Listing 4.1  Comment out a crucial line (QuizActivity.java)

@​O​v​e​r​r​i​d​e​ p​r​o​t​e​c​t​e​d​ ​v​o​i​d​ ​o​n​C​r​e​a​t​e​(​B​u​n​d​l​e​ ​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​ ​{​ ​ ​ ​ ​s​u​p​e​r​.​o​n​C​r​e​a​t​e​(​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​;​ ​ ​ ​ ​L​o​g​.​d​(​T​A​G​,​ ​"​o​n​C​r​e​a​t​e​(​)​ ​c​a​l​l​e​d​"​)​;​ ​ ​ ​ ​s​e​t​C​o​n​t​e​n​t​V​i​e​w​(​R​.​l​a​y​o​u​t​.​a​c​t​i​v​i​t​y​_​q​u​i​z​)​;​ ...

Get Android Programming: The Big Nerd Ranch Guide 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.