Kotlin and Android Development featuring Jetpack:Page 38, FragmentPickPlayerBinding class not found

On page 38, it calls for ediging the PickPlayersFragement class and add the following to the onCreateView() method:

val binding = FragmentPickPlayersBinding.inflate(inflater, container, false)

But the specified class doesn’t exist and I’m assuming is generated but isn’t/hasn’t been so.

Hey Darryl!
You are correct, FragmentPickPlayersBinding is generated for you if data binding is set up. Just to confirm, do you have fragment_pick_players.xml created in your layout folder?

Yes, there’s a file there with the changes from the applied to it up through page 37.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="16dp"
        tools:context=".fragments.PickPlayersFragment">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <include
                android:id="@+id/mainPlayer"
                layout="@layout/player_list_item" />

            <include
                android:id="@+id/player2"
                layout="@layout/player_list_item" />

            <include
                android:id="@+id/player3"
                layout="@layout/player_list_item" />

            <include
                android:id="@+id/player4"
                layout="@layout/player_list_item" />

            <include
                android:id="@+id/player5"
                layout="@layout/player_list_item" />

            <include
                android:id="@+id/player6"
                layout="@layout/player_list_item" />

        </LinearLayout>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:contentDescription="@string/play_button"
            android:src="@drawable/baseline_play_arrow_24"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:tint="@android:color/white" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

I’m assuming the issue here is the missing data binding flag, which was causing trouble with duplicated classes. Let me know if it’s still giving you trouble after that’s resolved.

1 Like

That’s correct. Once that and the appcompat version were set, this started working as expected.