Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
75

4. 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 QuizActivity.java, comment out the
code in onCreate(Bundle) where you pull out mQuestionTextView.


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


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate(Bundle) called");
setContentView(R.layout.activity_quiz);


if (savedInstanceState != null) {
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
}


// mQuestionTextView = (TextView)findViewById(R.id.question_text_view);


mTrueButton = (Button)findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener() {
...
});
...
}


http://www.ebook3000.com

Free download pdf