Chapter 20 Challenge 1

Hi all, in attempting to add a SeekBar to the activity_main, I find the following error after attempting to click any of the buttons (the SeekBar is fine):

java.lang.IllegalStateException: Could not find method @{(view) -> viewModel.onButtonClicked()(View) in a parent or ancestor Context for android:onClick attribute defined on view class androidx.appcompat.widget.AppCompatButton
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:436)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:393)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Here is activity_main:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context=".MainActivity" >

    </androidx.recyclerview.widget.RecyclerView>


    <androidx.appcompat.widget.AppCompatSeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:max="100"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/recycler_view" />


</androidx.constraintlayout.widget.ConstraintLayout>

Not done with this solution yet, but here is mainActivity:

class MainActivity : AppCompatActivity() {

private lateinit var beatBox: BeatBox
private lateinit var speedControlBar: SeekBar

private var speed: Float = 1.0f

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    beatBox = BeatBox(assets)

    val binding: ActivityMainBinding =
        DataBindingUtil.setContentView(this, R.layout.activity_main)

    binding.recyclerView.apply {
        layoutManager = GridLayoutManager(context, 3)
        adapter = SoundAdapter(beatBox.sounds)
    }

    speedControlBar = findViewById(R.id.seekbar)
    speedControlBar.setProgress(50)
    speedControlBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
        override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
            speed = (p1/50).toFloat()
            Log.d("MAIN", speed.toString())
        }

        override fun onStartTrackingTouch(p0: SeekBar?) {

        }

        override fun onStopTrackingTouch(p0: SeekBar?) {
        }
    })
} 
...

No changes to the rest of the code, but it’s already broken and I don’t know why. Any explanation is appreciated.