Errata pg 79? "onTextChanged" => "onClick"


#1

Below is an except of LogCat (similar to what is show in Figure 4.5).

[color=#BF4000]07-31 18:33:50.586: D/QuizActivity(31895): Updating question text for question #0
07-31 18:33:50.586: D/QuizActivity(31895): java.lang.Exception
07-31 18:33:50.586: D/QuizActivity(31895): at com.bignerdranch.android.geoquiz.QuizActivity.updateQuestion(QuizActivity.java:34)[/color] [color=#0080FF]<= 1st line[/color]
[color=#BF4000]07-31 18:33:50.586: D/QuizActivity(31895): at com.bignerdranch.android.geoquiz.QuizActivity.access$1(QuizActivity.java:33)[/color] [color=#0080FF]<= 2nd line[/color]
[color=#BF4000]07-31 18:33:50.586: D/QuizActivity(31895): at com.bignerdranch.android.geoquiz.QuizActivity$3.onClick(QuizActivity.java:91)[/color] [color=#0080FF]<= 3rd line[/color]
[color=#BF4000]07-31 18:33:50.586: D/QuizActivity(31895): at android.view.View.performClick(View.java:3526)
07-31 18:33:50.586: D/QuizActivity(31895): at android.view.View$PerformClick.run(View.java:14133)[/color]

The paragraph following that figure says “[color=#00BF00]The top line in the stack trace is the line where you logged the Exception[/color]”. Okay… that’s fine, but then it says, “[color=#00BF00]The line after that shows where the setter was called from – the implementation of onTextChanged(…). Double-click this line and you will be taken to where you set the title to the hard-coded string.”[/color]

  1. I think errata might be in order, but this is just FYI (assuming I’m not just confused).
    (a) it’s actually the third line that takes you to where the error was intentionally inserted
    (b) double-clicking takes you to where onClick() was implemented, not “onTextChanged()”, and
    © the bug we injected was commenting out the incrementing of mCurrentIndex (vs. setting “the title to the hard-coded string”)

  2. But what I’m really interested in, is can you talk a little bit about that mysterious “access$1” in the 2nd line of the stack trace, and about the “$1” and "3" (found in line 3) in general? Double-clicking the 2nd line takes us to the [b]updateQuestion()[/b] procedure declaration, so I'd assume it's just an extra reference in the stack that was injected by either the Android OS or at compile time... but why is it only included when we click the "Next" button, but it's not included in the first occurrence of our Exception in the LogCat (during launch when [b]updateQuestion()[/b] is called from [b]onCreate[/b])? And are the 's in the stack trace significant? I’m just curious to understand these things in case they might prove useful for future debugging.

If the answer is “ignore all of that stuff, it’s never helpful for debugging”, that’s fine too.

thx,
Frank


#2

1- Thanks for pointing this out. I’ll take a look in a minute and see if I can’t tease out a good correction.

2- Interesting question! You’re right that you could get by without knowing what access$1 is, but… well, where’s the fun in that?

This access$1 method is a little method injected by the Java compiler. It’s used when calling something in an inner class from an outer class, or calling an outer class method from an inner class.

In general, any time you see a dollar sign, something inner class related is going on. E.g. QuizActivity$3 is an anonymous inner class name - it’s anonymous inner class #3 in QuizActivity.