Kotlin and Android Development featuring Jetpack: Ch. 9 won't build

@mfazio23

I have copied / typed in all the code to the end of Ch. 9, but I cannot get the project to build. It keeps failing with the error:

“e: file:///C:/Users/derek/Dropbox/AndroidStudioProjects/AndroidBaseballLeague/app/src/main/java/com/example/abl/teams/TeamsGridAdapter.kt:43:17 Unresolved reference: setClickListener”

I’ve verified that the code for the TeamViewHolder inner class is identical to the provided code (by copying and pasting it), but it still fails. Android Studio has one suggestion for importing a function, but it then causes even more errors, so I think that may be the wrong function. Besides, that function is not imported in the provided Ch. 9 code.

I squashed a few typos in the Gradle files, but this is still happening, so I’m not sure where my problem is. Has something else changed in Android, or do I just have a typo I cannot find? Do you have any suggestions?

My repository is here: GitHub - dachristenson/Android_Baseball_League: Working through Part II of "Kotlin and Android Development Featuring Jetpack" by Michael Fazio.

Thanks for any help in advance!

The setClickListener function is an extra binding adapter on the ViewBindingAdapter class, so you would need an additional import there. That being said, I think that signature may have changed as well.

In reality, the better approach here is to use the setOnClickListener { ... } function on the view’s root:

root.setOnClickListener {
  ...
}

This is clearer and similar to how you normally handle click listeners in Android.

Since adding the function import suggested by Android Studio didn’t work (as above – it does, indeed, not like what the code tries to send in as parameters), I replaced “setClickListener {}” with “root.setOnClickListener {}” as you suggested. That did it! It now builds and runs correctly. Thanks!